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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

Can someone explain this DADX measure?

I am new to dax, and am having trouble trouble understanding this measure. Can someone who is familiar with dax break this down line by line and explain the code and functions? I feel it would be a great learning exercise for myself and perhaps others.

 

Actual =
VAR ACT = CALCULATE(SUM('COVID-19'[Cumulated]), LASTDATE('COVID-19'[Date]))
VAR PD = CALCULATE(CALCULATE(SUM('COVID-19'[Cumulated]), LASTDATE('COVID-19'[Date])),PREVIOUSDAY(LASTDATE('COVID-19'[Date])))

RETURN
IF (HASONEVALUE(TimeRange[Time Range]),
      SWITCH(VALUES(TimeRange[Time Range]),
              "Cumulated", ACT,
               "Daily", ACT - PD,
                BLANK()
      ),
      ACT
)
1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

Well that is some interesting code.

ACT - Calculates the sum of the Cumulated column in table COVID-19 within the context of the last date (latest date) within the Date column in the same COVID-19 table. So, looks like it is getting the last value from what is probably an accumulating total column.

PD - So, they wrap the same calculation as above in another CALCULATE and tag in a filter context of PREVIOUSDAY from the last date so this is basically getting the next to the last day.

In the RETURN statement, they check to see if a single value has been selected in the Time Range column in the TimeRange table. Probably a slicer. Maybe a disconnected table? If there is only one value, then it returns ACT variable.

If that is not the case, it gets the distinct values that have been selected and here I am fairly sure it just returns BLANK or an error all the time as it is unclear to that you can compare a table to a string. I have tested this and you cannot.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

Well that is some interesting code.

ACT - Calculates the sum of the Cumulated column in table COVID-19 within the context of the last date (latest date) within the Date column in the same COVID-19 table. So, looks like it is getting the last value from what is probably an accumulating total column.

PD - So, they wrap the same calculation as above in another CALCULATE and tag in a filter context of PREVIOUSDAY from the last date so this is basically getting the next to the last day.

In the RETURN statement, they check to see if a single value has been selected in the Time Range column in the TimeRange table. Probably a slicer. Maybe a disconnected table? If there is only one value, then it returns ACT variable.

If that is not the case, it gets the distinct values that have been selected and here I am fairly sure it just returns BLANK or an error all the time as it is unclear to that you can compare a table to a string. I have tested this and you cannot.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Nice explanation @Greg_Deckler  got in there before me and with a more succinct answer than I had in my head 😊

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.