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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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