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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
IgorM
Frequent Visitor

A measure calculating two different cumulative totals

Hi,

I need a measure that will calculate two different cumulative totals depanding on one of the column values. 

The below table contains a sample data set. The Date column is connected to a Calendar table in my model. For the following set I need to write a measure that will:

1) for Country=Poland calculate YTD cumulative total of Amount

2) for Country=UK calculate lifetime to date total of Amount. The following measure correctly calculates such a lifetime to date total but I don't know how to combine it in a single measure with the condition from point 1:  CALCULATE(SUM[Amount];FILTER(ALL('Calendar'[Date]);'Calendar'[Date]<=MAX('Calendar'[Date])))

 

CountryCityDateAmount
PolandGdansk09.06.2018458,14
PolandGdansk01.01.2019354,02
PolandKrakow11.06.2018678,38
PolandKrakow30.12.2018775,82
UKLondon02.09.2018995,06
UKLondon03.02.2019342,28
UKLondon09.05.2019528,65
UKCambridge16.06.2018499,19
2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

Should be something like:

 

Measure = 
VAR __country = MAX([Country])
RETURN
SWITCH(__country,
    "Poland",[Some measure],
    "UK",CALCULATE(SUM[Amount];FILTER(ALL('Calendar'[Date]);'Calendar'[Date]<=MAX('Calendar'[Date]))),
    BLANK()
)

You could also use an IF statement instead of SWITCH but SWITCH is usually better.



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...

Hi Greg,

 

no I am afraid it is not working the way I wanted it to work. Below is a complete measure code. I am testing it in Power Pivot that's why there is IF instead of SWITCH. It seems to me that the IF test always fails and therefore the false part of the if statement is always executed.

If the code was correct 2 should be returned for Gdansk, since there is only one entry for Gdansk with the date in 2019 (second row of the source table) - please notice that I have changed the amounts in the sample table for simplicity reasons.

 

Capture.PNG

 

 

=VAR __country = MAX(SourceData[Country])
RETURN
IF(__country="Poland";TOTALYTD(SUM(SourceData[Amount]);'Calendar'[Date]);
CALCULATE(SUM(SourceData[Amount]);FILTER(ALL('Calendar'[Date]);'Calendar'[Date]<=MAX('Calendar'[Date]))))

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.