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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register 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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.