Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Calculate row total percentage

I want to calculate Row percentage of product on row basis.

for example, I have dimCountry, dimProduct and FactTable, I put them in matrix visual as show below

 

What i want to achieve is percentage of country per product on row basis as shown below

How can I achieve this using dax

 

  • Hi Anonymous ,

    The DAX might change based on the FactTable Structure. But assuming the below is the FactTable structure, I have given the DAX

     

    You can use the below DAX for this

    Product% = 
    VAR Numerator = CALCULATE(SUM(FactTable[Numbers]), REMOVEFILTERS(dimCountry[Country]), VALUES(dimCountry[Country]))
    VAR Denominator = CALCULATE(SUM(FactTable[Numbers]), REMOVEFILTERS(dimProduct[Product]))
    RETURN
    DIVIDE(Numerator, Denominator)

     

    Set the format of the Product% to Percentage

     

    If you share the table structure may be that could help!!

     

    Regards,

2 Replies

  • Hi,

    Please check the below picture and the attached pbix file.

     

     

     

     

    Percentage measure: =
    VAR _bycountry =
        CALCULATE ( [Count measure:], ALLEXCEPT ( 'Fact', Country[Country] ) )
    RETURN
        IF ( HASONEVALUE ( Country[Country] ), DIVIDE ( [Count measure:], _bycountry ) )
    

     

  • Hi Anonymous ,

    The DAX might change based on the FactTable Structure. But assuming the below is the FactTable structure, I have given the DAX

     

    You can use the below DAX for this

    Product% = 
    VAR Numerator = CALCULATE(SUM(FactTable[Numbers]), REMOVEFILTERS(dimCountry[Country]), VALUES(dimCountry[Country]))
    VAR Denominator = CALCULATE(SUM(FactTable[Numbers]), REMOVEFILTERS(dimProduct[Product]))
    RETURN
    DIVIDE(Numerator, Denominator)

     

    Set the format of the Product% to Percentage

     

    If you share the table structure may be that could help!!

     

    Regards,