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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
oromerot
Frequent Visitor

Switch function

Hi PBI community, Im new in DAX and I hope you can help me 
I have 3 tables, A SellOut table, a Information Company Table and a Calendar Table
I've created a measure with switch:

Classification = SWITCH(TRUE(),

[%Avrg]>=0.8,"A",

[%Avrg]>=0.6,"B",

[%Avrg]<0.6,"C",

"Otro")
Then I put in a matrix visualization and works well but I need to count the Classification and put it in a pie chart

Company%AvrgClassification
Store10.9A
Store20.5C
Store30.4C

So I tried to put that measure as a column but it give me incorrect results
The measure %Avrg
%Avrg= CALCULATE(DIVIDE([Actual_Month_Avrg],[Last_Month_Avrg],1))

          Actual_Month_Avrg= CALCULATE(DIVIDE([Sales],[Days_Use]))

          Last_Month_Avrg= CALCULATE(DIVIDE([Sales],[Days_Use]),DATEADD(CalendarTable[Date],-1,MONTH))
                 Sales= Sum(Sell_Out[Sales])
                 Days_Use= 
DISTINCTCOUNT(Sell_Out[Date])
thanks in advance

2 REPLIES 2
v-deddai1-msft
Community Support
Community Support

Hi @oromerot ,

 

You can create a table2 like :

Capture.PNG

Then you can use the following measure to count Classification:

 

 

Measure =
CALCULATE (
    DISTINCTCOUNT ( Table[Company] ),
    FILTER ( Table, [Classification] = MAX ( Table2[Classification] ) )
)

 

 

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

 

Best Regards,

Dedmon Dai

amitchandak
Super User
Super User

@oromerot , Create a table class with three values A,B,C, you can create using enter data.

 

then try a measure like

measure =
var _cal =Classification = SWITCH(TRUE(),
[%Avrg]>=0.8,"A",
[%Avrg]>=0.6,"B",
[%Avrg]<0.6,"C",
"Otro")
return
calculate(countrows(Table[Company]), values(Table[Company]) filter(Table, _cal = max(class[Class])))

 

refer these

https://www.daxpatterns.com/dynamic-segmentation/
https://www.daxpatterns.com/static-segmentation/
https://www.poweredsolutions.co/2020/01/11/dax-vs-power-query-static-segmentation-in-power-bi-dax-po...
https://radacad.com/grouping-and-binning-step-towards-better-data-visualization

https://radacad.com/dynamic-banding-or-grouping-in-power-bi-using-dax-measures-choose-the-size-of-bi...
https://www.credera.com/blog/technology-solutions/creating-aging-report-using-a-user-selected-date-i...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors