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
Xilitor01
Helper III
Helper III

Calculate percent based on multiple columns

Hello,

 

Is it possible to calculate percentage when MARA-MTART, LOCATIONTYPE and LOCATIONID are the same - like the example below.

So adding an extra column calculating the percentage where the three first columns have the same output.

Xilitor01_0-1635181678050.png

 

I hope you can help - thank you! 🙂

 

1 ACCEPTED SOLUTION

Hi @Xilitor01 ,

IF the "Mat Nr Count" is a measure, you can modify M like this.

vkalyjmsft_0-1635409559545.png

 

Best Regards,
Community Support Team _ kalyj

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

8 REPLIES 8
v-yanjiang-msft
Community Support
Community Support

Hi @Xilitor01 ,

According to your description, here's my solution.

M =
VAR _CURRENTDATA =
    CALCULATE ( SUM ( 'dummy data'[Mat Nr Count] ) )
VAR _Total =
    SUMX (
        FILTER (
            ALL ( 'dummy data' ),
            'dummy data'[MARA-MTART] = MAX ( 'dummy data'[MARA-MTART] )
                && 'dummy data'[LOCATIONTYPE] = MAX ( 'dummy data'[LOCATIONTYPE] )
                && 'dummy data'[LOCATIONID] = MAX ( 'dummy data'[LOCATIONID] )
        ),
        'dummy data'[Mat Nr Count]
    )
RETURN
    DIVIDE ( _CURRENTDATA_Total )

vkalyjmsft_1-1635325682448.png

 

Best Regards,
Community Support Team _ kalyj

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

I can see your solutions works perfect on the dummy data - very impressive!
I do have one question as I've made a mistake when I did the dummy pbix file.

The "Mat Nr Count" is a calculated measure:

Mat Nr Count= SUMX (
VALUES ( MODELVIEW[LOCATIONID] ),
CALCULATE ( DISTINCTCOUNT ( MODELVIEW[MATNR] ) )
)
 
Is it possible to do the same but with this as the "Mat Nr Count" measure?

Once again: Thank you so much! 🙂

Hi @Xilitor01 ,

IF the "Mat Nr Count" is a measure, you can modify M like this.

vkalyjmsft_0-1635409559545.png

 

Best Regards,
Community Support Team _ kalyj

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

Thank you very much! 🙂

Fowmy
Super User
Super User

@Xilitor01 

Can you try the following Measure:

M =
DIVIDE (
    CALCULATE ( DISTINCTCOUNT ( TableName[MatNr] ) ),
    SUMX (
        ADDCOLUMNS (
            CALCULATETABLE (
                TableName,
                ALLEXCEPT (
                    TableName,
                    TableName[MARA-MTART],
                    TableName[LOCATIONTYPE],
                    TableName[LOCATIONID]
                )
            ),
            "DC", CALCULATE ( DISTINCTCOUNT ( TableName[MatNr] ) )
        ),
        [DC]
    )
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hi Fowmy,

 

Thank you for your response. Unfortunately it doesn't calculate correctly.

The "M" should calculate like "Frequency" in this example as I've put in my filters based on the three first columns:

Xilitor01_0-1635237731953.png

 

@Xilitor01 

Create a sample Power BI file with dummy data and share the link here. You can save in Google drive. 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hi Fowmy,

 

You can download it here:

https://easyupload.io/ntarp8

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.