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

Dynamic Columns based on Slicer selection

Hello,

 

I have below sample data with 4 Columns. 

 

CountryAccountYearValue
AUSEBITDA202213
AUSEBITDA202310
AUSEBITDA201898
AUSEBITDA2021120
AUSEBITDA2020700
AUSEBITDA201910
AUSSales202013
AUSSales202110
AUSSales202339
AUSSales2019120
AUSSales2018145
AUSSales202228
AUSITDA202310
AUSITDA2022231
AUSITDA202139

 

When User selects 2020 from Slicer, Clustered Chart should display below Columns only :-

  1. EBITDA for 2020 and last 2 years (2020, 2019 and 2018).
  2. Sales for 2020 only
  3. ITDA for next 2 years (i.e. 2021 and 2022)

Chart shall be displayed as per below:-

Sekhar1_0-1665078479824.png

 

 

 

Can you please advise on how to get the above result?

 

 

 

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Sekhar1 ,

 

Here I suggest you to try this code to create a measure.

Measure = 
VAR _SELECTYEAR = SELECTEDVALUE('Table 2'[Year])
VAR _VALUE = 
IF(
    ISFILTERED('Table 2'[Year]),
    SWITCH(
        MAX('Table'[Account]),
        "EBITDA",
        CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year]>=_SELECTYEAR-2&&'Table'[Year]<=_SELECTYEAR)),
        "Sales",
        CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year]=_SELECTYEAR)),
        "ITDA",
        CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year]>_SELECTYEAR&&'Table'[Year]<=_SELECTYEAR+2))
        )
    )
RETURN
_VALUE

Result is as below.

RicoZhou_0-1665126729454.png

 

Best Regards,
Rico Zhou

 

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

1 REPLY 1
v-rzhou-msft
Community Support
Community Support

Hi @Sekhar1 ,

 

Here I suggest you to try this code to create a measure.

Measure = 
VAR _SELECTYEAR = SELECTEDVALUE('Table 2'[Year])
VAR _VALUE = 
IF(
    ISFILTERED('Table 2'[Year]),
    SWITCH(
        MAX('Table'[Account]),
        "EBITDA",
        CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year]>=_SELECTYEAR-2&&'Table'[Year]<=_SELECTYEAR)),
        "Sales",
        CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year]=_SELECTYEAR)),
        "ITDA",
        CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year]>_SELECTYEAR&&'Table'[Year]<=_SELECTYEAR+2))
        )
    )
RETURN
_VALUE

Result is as below.

RicoZhou_0-1665126729454.png

 

Best Regards,
Rico Zhou

 

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

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.