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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
pamsardinha
Frequent Visitor

Calculated measure does not work with data hierarchy

Hello,

 

I am trying to calculate the saldo absolute change between months, therefore created two measures:
1. this one gets the saldo by the end of month:

 

 

SaldoEOM =
VAR Latest_Date = MAX('Table'[Date])
RETURN
    CALCULATE (SUM('Table'[Saldo]), 'Table'[Date] = Latest_Date)

 

 

 

2. this one gets the saldo by the end of previous month:

 

 

Saldo End of Previous Month = 
VAR Endmonth = EOMONTH(max('Table'[Date]), -1) 
RETURN
    CALCULATE(
        [SaldoEOM],
        'Table'[Date] = Endmonth
    )

 

 

 

The issue is when I try to use in the a table with date hierarchy (only Year and Month), the 'Saldo End of Previous Month' shows nothing, areas when I use the whole date, I can see the result.

 

The first one works perfectly fine, so the problem is not with the date format/hiearchy.

I tried several different options to calculate this second part, but without success. Any better idea?

Thank you.

1 ACCEPTED SOLUTION

Hi, once again thank you for the reply.

I was able to work around by using the following dax syntax, just adding "ALLEXCEPT" at the end.

Now it works with the date hierarchy Year, Month.


By using ALLEXCEPT I removed all filters from Table1, except the ones I needed to get the right result 'Table1'[Saldo], 'Table1'[Date], 'Table2'[System], 'Table3'[variable1], 'Table4'[variable1]

 

*I changed the name of the measure to be more concise

 

 

SaldoEPM =
CALCULATE(SUM('Table1'[Saldo]),
        'Table1'[Date] = EOMONTH(max('Table1'[Date]),-1),
        ALLEXCEPT('Table1', 'Table1'[Saldo], 'Table1'[Date], 'Table2'[System],  'Table3'[variable1],'Table4'[variable1]))

 

 

 

The result now looks something like this:

YearMonthSaldoEPMSaldoEOMSaldoChangeSystem
2023Jan01010A
2023Feb102010A
2023Mar2012-8A
2023Apr12153A
2023May15205A
2023Jun205030A
2023Jan06565O
2023Feb6542-23O
2023Mar429553O
2023Apr9556-39O
2023May5652-4O
2023Jun 5050O

 

I only have the issue now that the SALDOEPM to calculate the differece from june of system O, is not recognizing the value from May. But I will open another ticket to this issue, since the issue here was working with date hierarchy and now it works! 

View solution in original post

4 REPLIES 4
pamsardinha
Frequent Visitor

Thank you for your reply @NaveenGandhi !

Unfortunetely I am working with powerbi dataset and I cannot create tables since I have no rights to do it.

@pamsardinha 

If thats the case, Use a measure like below.

Previous_amt =
CALCULATE (
SUM ( 'Previous Indemnity'[Amount] ),
ALL ( 'Previous Indemnity' ),
PREVIOUSMONTH ( 'Previous Indemnity'[Transaction Date] )
)

If you still have issues, Share sample data or PBIX.
 
 
If this post helps, then please consider Accept it as the solution to help the others find it more quickly. Appreciate your kudos!!
NaveenGandhi
Super User
Super User

Hello @pamsardinha 

Try Dax like this.

Previous_amt = CALCULATE(
        sum('Amount),
        PREVIOUSMONTH('Calendar'[Date])
    )

Create a calendar table with a relationship between your table and calendar. Use the calendar[month]/Year in slicer, table hierarchy and measure above. You should be able to acheive something as below.
NaveenGandhi_0-1685717100117.png
 
Let me know if this helps or if you have any question.
 
If this post helps, then please consider Accept it as the solution to help the others find it more quickly. Appreciate your kudos!!

Hi, once again thank you for the reply.

I was able to work around by using the following dax syntax, just adding "ALLEXCEPT" at the end.

Now it works with the date hierarchy Year, Month.


By using ALLEXCEPT I removed all filters from Table1, except the ones I needed to get the right result 'Table1'[Saldo], 'Table1'[Date], 'Table2'[System], 'Table3'[variable1], 'Table4'[variable1]

 

*I changed the name of the measure to be more concise

 

 

SaldoEPM =
CALCULATE(SUM('Table1'[Saldo]),
        'Table1'[Date] = EOMONTH(max('Table1'[Date]),-1),
        ALLEXCEPT('Table1', 'Table1'[Saldo], 'Table1'[Date], 'Table2'[System],  'Table3'[variable1],'Table4'[variable1]))

 

 

 

The result now looks something like this:

YearMonthSaldoEPMSaldoEOMSaldoChangeSystem
2023Jan01010A
2023Feb102010A
2023Mar2012-8A
2023Apr12153A
2023May15205A
2023Jun205030A
2023Jan06565O
2023Feb6542-23O
2023Mar429553O
2023Apr9556-39O
2023May5652-4O
2023Jun 5050O

 

I only have the issue now that the SALDOEPM to calculate the differece from june of system O, is not recognizing the value from May. But I will open another ticket to this issue, since the issue here was working with date hierarchy and now it works! 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors