Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
elatreille
Helper I
Helper I

Today()-1 vs Today()-2

Hi all,

 

I need to display in a column graph data from 2 days and yesterday.

So the chart will easilly show the 2 days trend.

I used this in Power BI desktop and it works well but when gets time to show on Power BI Service, it only shows yesterday but takes the place of the 2 days graph... its like Power BI doesn't like when we use Today() twice in the same graph.

 

Here are my 2 measures:

Yesterday = CALCULATE(SUM('AdvRev'[Total impressions]),'Calendar'[Date]=TODAY()-1)

Two_Days = CALCULATE(SUM('AdvRev'[Total impressions]),'Calendar'[Date]=TODAY()-2)

2017-06-12_23-01-18.png

 

 

So what did I do wrong?

1 ACCEPTED SOLUTION

@elatreille,

 

You could also create measures as shown below.

Yesterday =
SUMX (
    FILTER ( AdvRev, AdvRev[Date] = MAX ( AdvRev[Date] ) - 1 ),
    AdvRev[Total impressions]
)
Two_Days =
SUMX (
    FILTER ( AdvRev, AdvRev[Date] = MAX ( AdvRev[Date] ) - 2 ),
    AdvRev[Total impressions]
)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
elatreille
Helper I
Helper I

OK, I found a way to do so but this is a kind of patch... I am pretty sure there is a way to do it better so I will continue my research on it. Here is what I did:

 

Yesterday = SUM(AdvRev[Total impressions]) - CALCULATE(SUM('AdvRev'[Total impressions]),DATEADD('AdvRev'[Date],-1, DAY))

 

Where: SUM(AdvRev[Total impressions]) returns the total impressions since day one and CALCULATE(SUM('AdvRev'[Total impressions]),DATEADD('AdvRev'[Date],-1, DAY)) returns the total impressions before yesterday.

So SUM(AdvRev[Total impressions]) - CALCULATE(SUM('AdvRev'[Total impressions]),DATEADD('AdvRev'[Date],-1, DAY)) = the impressions served Yesterday only

 

Two_Days = SUM(AdvRev[Total impressions]) - (CALCULATE(SUM('AdvRev'[Total impressions]),DATEADD('AdvRev'[Date],-2, DAY)) + 'AdvRev'[Yesterday])

 

I did the same calculation from first day to 2 days before and added the yesterday impressions...

 

Let me know if someone has a better solution 😉

@elatreille,

 

You could also create measures as shown below.

Yesterday =
SUMX (
    FILTER ( AdvRev, AdvRev[Date] = MAX ( AdvRev[Date] ) - 1 ),
    AdvRev[Total impressions]
)
Two_Days =
SUMX (
    FILTER ( AdvRev, AdvRev[Date] = MAX ( AdvRev[Date] ) - 2 ),
    AdvRev[Total impressions]
)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
GilbertQ
Super User
Super User

Hi there, 

 

What about if you change your measure from TODAY() to use DATEADD

 

Here is an example: 

Yesterday = CALCULATE(SUM('AdvRev'[Total impressions]),DATEADD('Calendar'[Date],-1, DAY))




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Both ways works for yesterday but not working for 2 daus ago so if I replace -1 by -2 for 2 days before, it returns the same numbers from yesterday.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.