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

Previous years sum by year and current year sum by quarter in the same clustered column chart

Hello there,

 

suppose I have a dataset like:

FruitTime
Apple2021/01/23
Apple2022/05/23
Pear2023/01/01
Watermelon2021/01/26
Apple2022/01/26
Pear2022/03/26
Watermelon2023/03/26
Pear2023/06/26
Apple2023/08/26
Pear2023/12/26

 

Is it possible that I can have a clustered column chart like this to show the count of fruit by year if is before 2023 and quarter if is in 2023(Ignore the numbers lol):

Mikazuki_0-1681109587146.png

 

Thanks for your help!!!

 

1 ACCEPTED SOLUTION
PawarNovil
Frequent Visitor

Hi @Mikazuki ,

 

Please try below steps- 

1. create a KPI grouping table-

KPIGrouping = DATATABLE( "KPI", STRING,
                        "Sort", INTEGER,
                         { {"2021", 1 },
                          {"2022",2},
                          {"YTD2023",3},
                          {"1st Quarter",4},
                          {"2nd Quarter",5},
                          {"3rd Quarter",6},
                          {"4th Quarter", 7}
                          }
)
------------------------------------------------------
2. create measures for your individual KPI's (2021, 2022, YTD2023,....) based on your required result and filter context.
for example -
Count2021 = 
CALCULATE(COUNTA(FruitTable[Fruit]),  year(FruitTable[Date])=2021)
Count2022=CALCULATE(DISTINCTCOUNT(FruitTable[Fruit]), FILTER(FruitTable, year(FruitTable[Date])=2022))
--------------------------------------------------------
3.  create visual and use KPI  from KPIGrouping table and cretae a measure as below
-----------------------
KPI Grouping Cluster Chart =
var selectedKPI=SELECTEDVALUE(KPIGrouping[KPI],"2021")
var currentkpi = switch (
selectedKPI,
"2021", [Count2021],
"2022",[Count2022],
"YTD2023",[Count2023YTD],
 "1st Quarter",2,  // Put your 1st Quarter measure name in place of 2
"2nd Quarter",1, // Put your 2nd Quarter measure name in place of 1
"3rd Quarter",1,  // Put your 3rd Quarter measure name in place of 1
"4th Quarter", 1, // Put your 4th Quarter measure name in place of 1
blank()
)
return
currentkpi
---------------------------------------------------------------------------------------------
PawarNovil_0-1681212568877.png

 

 

--------------------------------------------------------------------------------------------------------------------

 

Regards,

Novil

If I answer your question, please mark my post as a solution.

View solution in original post

3 REPLIES 3
PawarNovil
Frequent Visitor

Hi @Mikazuki ,

 

Please try below steps- 

1. create a KPI grouping table-

KPIGrouping = DATATABLE( "KPI", STRING,
                        "Sort", INTEGER,
                         { {"2021", 1 },
                          {"2022",2},
                          {"YTD2023",3},
                          {"1st Quarter",4},
                          {"2nd Quarter",5},
                          {"3rd Quarter",6},
                          {"4th Quarter", 7}
                          }
)
------------------------------------------------------
2. create measures for your individual KPI's (2021, 2022, YTD2023,....) based on your required result and filter context.
for example -
Count2021 = 
CALCULATE(COUNTA(FruitTable[Fruit]),  year(FruitTable[Date])=2021)
Count2022=CALCULATE(DISTINCTCOUNT(FruitTable[Fruit]), FILTER(FruitTable, year(FruitTable[Date])=2022))
--------------------------------------------------------
3.  create visual and use KPI  from KPIGrouping table and cretae a measure as below
-----------------------
KPI Grouping Cluster Chart =
var selectedKPI=SELECTEDVALUE(KPIGrouping[KPI],"2021")
var currentkpi = switch (
selectedKPI,
"2021", [Count2021],
"2022",[Count2022],
"YTD2023",[Count2023YTD],
 "1st Quarter",2,  // Put your 1st Quarter measure name in place of 2
"2nd Quarter",1, // Put your 2nd Quarter measure name in place of 1
"3rd Quarter",1,  // Put your 3rd Quarter measure name in place of 1
"4th Quarter", 1, // Put your 4th Quarter measure name in place of 1
blank()
)
return
currentkpi
---------------------------------------------------------------------------------------------
PawarNovil_0-1681212568877.png

 

 

--------------------------------------------------------------------------------------------------------------------

 

Regards,

Novil

If I answer your question, please mark my post as a solution.

Mikazuki
Frequent Visitor

Dear Pat,

 

I see the link that you attached but I still cannot get the data like 2023YTD as an individual part from the graph, could you please help me with the dax function with the sample data that I listed before? Thanks.

ppm1
Solution Sage
Solution Sage

You can do that with calculation groups.

Introducing Calculation Groups - SQLBI

 

Pat

Microsoft Employee

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.

Top Solution Authors
Top Kudoed Authors