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
Stiphn
Frequent Visitor

Returning Year N and N-1 values in a measure for Waterfall use

Dear all,

Basically, my use case could be seen as very similar to this post: https://community.powerbi.com/t5/Desktop/Dynamic-Waterfall-Chart-toggle-between-Budget-Forecast-Budg...

Building something similar, I am stuck at the LY vs CY comparison.

I am using a P&L Data table with Value, Date, Reporting types. I have a Date table with a relation ship to P&L Data.

Stiphn_0-1642553324868.png

 

Trying to return a measure with data from a month in year N and N-1, I managed to get to this code

 

Selected Waterfall Value = 
CALCULATE( 
     SUM('P&L Data'[YTDAmountEUR]),  
     FILTER(
          ALL('Calendar'[Year]),
          'Calendar'[Year]=SELECTEDVALUE('Calendar'[Year]) || 'Calendar'[Year]=SELECTEDVALUE('Calendar'[Year])-1),
      EXCEPT(CALCULATETABLE(VALUES('P&L Data'[Reporting Type])),{"B","RF3","RF8"}))
  

 

This however return a single value for Year N, which combine N and N-1 value.
Can you please help me understand what I am doing wrong?

At the link is my sample (there is a lot in it as I also plan to include YTD/MTD switch sorry for the clutter): https://1drv.ms/u/s!Anpv9-Qk39aJga1xddadQo8PLggBVQ?e=Ef9Vou

 

Many thanks!

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Stiphn ,

 

In which visual would you like to use this measure? I find that the visualization in the image below is not affected by "Year" slicer.

Icey_0-1643013349308.png

 

If you just want to use in this visual, try this:

 

Icey - Selected Waterfall Value = 
VAR SelectedYear_ =
    SELECTEDVALUE ( 'Calendar'[Year] )
RETURN
    CALCULATE (
        SUM ( 'P&L Data'[YTDAmountEUR] ),
        'Calendar'[Year] = SelectedYear_,
        EXCEPT (
            CALCULATETABLE ( VALUES ( 'P&L Data'[Reporting Type] ) ),
            { "B", "RF3", "RF8" }
        )
    )

 

 

If you want to use it in a filtered visual, try this:

 

Icey - Selected Waterfall Value 2 =
VAR MaxFactYear_ =
    CALCULATE ( MAX ( 'P&L Data'[Year_] ), ALL ( 'Calendar'[Year] ) )
VAR FactYear_ =
    SELECTEDVALUE ( 'Calendar'[Year] )
RETURN
    IF (
        MaxFactYear_ <= MAX ( 'Calendar'[Year] )
            && MaxFactYear_ >= FactYear_ - 1,
        CALCULATE (
            SUM ( 'P&L Data'[YTDAmountEUR] ),
            ALL ( 'Calendar'[Year] ),
            EXCEPT (
                CALCULATETABLE (
                    VALUES ( 'P&L Data'[Reporting Type] ),
                    ALL ( 'Calendar'[Year] )
                ),
                { "B", "RF3", "RF8" }
            )
        )
    )

 

Icey_1-1643017194383.png

 

 

Best Regards,

Icey

 

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
Icey
Community Support
Community Support

Hi @Stiphn ,

 

In which visual would you like to use this measure? I find that the visualization in the image below is not affected by "Year" slicer.

Icey_0-1643013349308.png

 

If you just want to use in this visual, try this:

 

Icey - Selected Waterfall Value = 
VAR SelectedYear_ =
    SELECTEDVALUE ( 'Calendar'[Year] )
RETURN
    CALCULATE (
        SUM ( 'P&L Data'[YTDAmountEUR] ),
        'Calendar'[Year] = SelectedYear_,
        EXCEPT (
            CALCULATETABLE ( VALUES ( 'P&L Data'[Reporting Type] ) ),
            { "B", "RF3", "RF8" }
        )
    )

 

 

If you want to use it in a filtered visual, try this:

 

Icey - Selected Waterfall Value 2 =
VAR MaxFactYear_ =
    CALCULATE ( MAX ( 'P&L Data'[Year_] ), ALL ( 'Calendar'[Year] ) )
VAR FactYear_ =
    SELECTEDVALUE ( 'Calendar'[Year] )
RETURN
    IF (
        MaxFactYear_ <= MAX ( 'Calendar'[Year] )
            && MaxFactYear_ >= FactYear_ - 1,
        CALCULATE (
            SUM ( 'P&L Data'[YTDAmountEUR] ),
            ALL ( 'Calendar'[Year] ),
            EXCEPT (
                CALCULATETABLE (
                    VALUES ( 'P&L Data'[Reporting Type] ),
                    ALL ( 'Calendar'[Year] )
                ),
                { "B", "RF3", "RF8" }
            )
        )
    )

 

Icey_1-1643017194383.png

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Stiphn
Frequent Visitor

Thanks, it is working perfectly

Many thanks it works as intended!

amitchandak
Super User
Super User

@Stiphn , Try like

 

Selected Waterfall Value =
var _max = maxx(allselected('Calendar'), 'Calendar'[Year])
var _min =_max -1
CALCULATE(
SUM('P&L Data'[YTDAmountEUR]),
FILTER(
ALL('Calendar'[Year]),
'Calendar'[Year]=<= _Max && 'Calendar'[Year] >= _min ),
EXCEPT(CALCULATETABLE(VALUES('P&L Data'[Reporting Type])),{"B","RF3","RF8"}))

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.