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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
pr92
Frequent Visitor

ALL and ALLSELECTED in the same measure

I have the following data in my table : 

 

Segment   Category   Sales   Country
Old                 O         5200FR
Old                  3200FR
New               O         5900FR
New                1200FR
Recent           O         3500FR
Recent            5400FR
New               O         4200IT
New                 2500IT
Recent           O          1200IT
Recent             3500IT
Old                 O          9500IT
Old                   1400IT

 

In my report, I have a slicer by country.  I display the data of 1 country at a time.

 

I need to calculate the % of Sales where Category = 'O' on the total sales of the Segment.

 

For example, Slicer = FR, For the Segment = 'Old', the measure should return 61.9% ( = 5200 / (5200+3200) )

 

To do this I tried the following :

 

CategoryO_%Sales_PerSegment =

DIVIDE (
     CALCULATE (
        SUMTable[Sales] )
        ,Table[Category] = "O"
    ),
   CALCULATE (
        SUM ( Table[Sales] )
        , ALL( Table[Category])
    )
)
 
This does not take in consideration the slicer for country.
 
Is there a way I can add 
 ALLSELECTED (  Table[Country] ) in addition to ALL( Table[Category]) in the same measure ?
 
Thank you in advance
2 ACCEPTED SOLUTIONS
Dangar332
Super User
Super User

hi, @pr92 

 

what about other two record old(7500,2400) present with same country(FR)

Dangar332_1-1709818022763.png

 


if it also considerd then use below code

Measure 2 = 
var a = CALCULATE(SUM('Table (2)'[Sales   ]),ALL('Table (2)'[Category   ]))
var b = SUM('Table (2)'[Sales   ])
return
DIVIDE(b,a)



Dangar332_0-1709817984442.png

country =fr,segment =old , category=O, 12700/18300=0.69

change measure to percantage

 

 

View solution in original post

v-zhouwen-msft
Community Support
Community Support

@Dangar332 Thanks for the quick reply.

Hi @pr92 ,

It is possible to use both the 'ALL' function and the 'ALLSELECTED' function in the same measure. But when you apply the 'Country' field to the 'ALLSELECTED' function and no value in the slicer is selected. The 'Country' field loses its filtering effect, which can lead to data errors. If you insist on doing so, I have modified the dax expression you provided.

CategoryO_%Sales_PerSegment = 
VAR _a = SUMX(FILTER('Tabelle1','Tabelle1'[Category] = "O"),[Sales])
VAR _b = DIVIDE( _a,CALCULATE(SUM(Tabelle1[Sales]),ALL(Tabelle1[Category]), ALLSELECTED('Tabelle1'[Country]))
)
RETURN
IF(ISBLANK(_b),BLANK(),_b)

 

Final output:

vzhouwenmsft_0-1709883233998.png

Best Regards,
Wenbin 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

2 REPLIES 2
v-zhouwen-msft
Community Support
Community Support

@Dangar332 Thanks for the quick reply.

Hi @pr92 ,

It is possible to use both the 'ALL' function and the 'ALLSELECTED' function in the same measure. But when you apply the 'Country' field to the 'ALLSELECTED' function and no value in the slicer is selected. The 'Country' field loses its filtering effect, which can lead to data errors. If you insist on doing so, I have modified the dax expression you provided.

CategoryO_%Sales_PerSegment = 
VAR _a = SUMX(FILTER('Tabelle1','Tabelle1'[Category] = "O"),[Sales])
VAR _b = DIVIDE( _a,CALCULATE(SUM(Tabelle1[Sales]),ALL(Tabelle1[Category]), ALLSELECTED('Tabelle1'[Country]))
)
RETURN
IF(ISBLANK(_b),BLANK(),_b)

 

Final output:

vzhouwenmsft_0-1709883233998.png

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

Dangar332
Super User
Super User

hi, @pr92 

 

what about other two record old(7500,2400) present with same country(FR)

Dangar332_1-1709818022763.png

 


if it also considerd then use below code

Measure 2 = 
var a = CALCULATE(SUM('Table (2)'[Sales   ]),ALL('Table (2)'[Category   ]))
var b = SUM('Table (2)'[Sales   ])
return
DIVIDE(b,a)



Dangar332_0-1709817984442.png

country =fr,segment =old , category=O, 12700/18300=0.69

change measure to percantage

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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