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
SteveODea
Helper I
Helper I

Help with DAX syntax - measure to create a percentage

Hi there!

 

I am struggling with my DAX syntax and was hoping that someone could help me.

 

I have a measure which counts rows but includes a filter option

 

CountOfItems = CALCULATE(DISTINCTCOUNT('Table1'[Ref]), LEFT('Table1'[Desc],3) <> "Acc")
 
This works fine and when I put this into a matrix visualisation this gives me everything I need.
 
Untitled.png
 
I now need to create a table underneath this which shows the percentages of the total in each field.
 
Pretty simple, and I know I need to divide by the total figure (4,169) and use ALL or ALLSELECTED, but as I'm new to DAX, I'm struggling with the syntax a bit
 
This is what I've attempted, but is not working
 
%cOUNT = CALCULATE(DISTINCTCOUNT('Table1'[Ref]), LEFT('Table1'[Desc],3) <> "Acc")/
CALCULATE(ALL(DISTINCTCOUNT('Table1'[Ref])), LEFT('Table1'[Desc],3) <> "Acc")
1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @SteveODea 

 

What @Greg_Deckler  said or adjust your syntax to.

%cOUNT = 
DIVIDE(
    CALCULATE(
        DISTINCTCOUNT( 'Table1'[Ref] ), 
        LEFT( 'Table1'[Desc], 3 ) <> "Acc"
    ),
    CALCULATE(
        DISTINCTCOUNT( 'Table1'[Ref] ), 
        ALL( 'Table1' ),
        LEFT('Table1'[Desc],3) <> "Acc"
    )
)

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

View solution in original post

4 REPLIES 4
Mariusz
Community Champion
Community Champion

Hi @SteveODea 

 

What @Greg_Deckler  said or adjust your syntax to.

%cOUNT = 
DIVIDE(
    CALCULATE(
        DISTINCTCOUNT( 'Table1'[Ref] ), 
        LEFT( 'Table1'[Desc], 3 ) <> "Acc"
    ),
    CALCULATE(
        DISTINCTCOUNT( 'Table1'[Ref] ), 
        ALL( 'Table1' ),
        LEFT('Table1'[Desc],3) <> "Acc"
    )
)

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Thanks @Mariusz you're a legend!

 

I wasn't sure where to put the ALL function, and even now I know where it should go I don't really understand it, but it works!

 

I guess that's a battle for another day.

 

I also changed ALL to ALLSELECTED as I have some filters on the page but it's what I want and I have full control over the formatting too!

 

Cheers buddy!

Greg_Deckler
Super User
Super User

Try click the drop down arrow for the field in the Values area and choose Show As | Percent of Grand Total or Percent of Row/Column Total.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Great thanks @Greg_Deckler  that's a useful tip to know, which works.

 

The only problem I have now is I cannot format the %age as shown. All the percentages show with 2 decimal places but I am unable to change this.

 

I have tried selecting "Value Decimal Places" under Field Formatting in the Format Tile, but it appears to be stuck on "Auto"

 

Any ideas how to change this?

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.