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
AmiraBedh
Resident Rockstar
Resident Rockstar

Calculate the sum of the orders based on one row instead of the replicated value for all rows

I have the following Excel file which is imported to Power BI and it tracks the status for each order made by a client: 

Client   Order Status Quantity

1          345     1         20

1          345     2         20

1          345     3         20

2          567     1         12

2          567     2         12

2          567     3         12

 

I want to calculate the quantity like below :

Client   Order Status Quantity

1          345     1         20

1          345     2         20

1          345     3         20

1          567     1         12

1          567     2         12

1          567     3         12

Total                          32

It is like summing the distinct quantity for each Order which is 20+12=32 for each Client

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
1 ACCEPTED SOLUTION
amirabedhiafi
Impactful Individual
Impactful Individual

YourMeasure=

     var CountAll = SUM('yourTable'[Quantity])

     var CountUnique =CALCULATE(SUM('yourTable'[Quantity]), 'yourTable'[Status]=1)

  return IF(HASONEVALUE('yourTable'[Quantity]), CountAll,CountUnique)

     

Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini

View solution in original post

4 REPLIES 4
amirabedhiafi
Impactful Individual
Impactful Individual

YourMeasure=

     var CountAll = SUM('yourTable'[Quantity])

     var CountUnique =CALCULATE(SUM('yourTable'[Quantity]), 'yourTable'[Status]=1)

  return IF(HASONEVALUE('yourTable'[Quantity]), CountAll,CountUnique)

     

Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini

Worked like charm ! 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
SpartaBI
Community Champion
Community Champion

@AmiraBedh try this:
Measure = SUMX(VALUES('Table'[Order]), CALCULATE(MAX('Table'[Quantity])))

It doesn't give me the expected ouput


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

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.