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

Distinct sum based on two columns

Hi Community,

 

Tried to count how many products the employee worked, sounds easy at the beggining but I cant count the second column.

 

Tried usuing

DISTINCTCOUNTNOBLANK, but I can´t tell PBI to merge shift1+shift2 and give me a single result.
 
Also tried some suggestions with sumx but the data is a string, and I got errors.
 
Thanks in advance for any help...

 

   Desire results
ProductShift1Shift2NameProductsWorked
aWadeBrianWade2
bDaveRobertoDave3
cSethRamonSeth4
dBrian Brian3
eRobertoRileyRoberto2
fRamonGilbertRamon3
gJorgeGilbertJorge1
h DanGilbert5
iBrianWadeRiley1
jRobertoDaveDan1
kRamonSeth  
lRamonBrian  
m Dave  
nGilbertRamon  
oGilbertSeth  
pGilbertSeth  
1 ACCEPTED SOLUTION

Hi @Aucesar 

You can refer to the following measure

1.Create a table to diaplay the user

2.Then create a measure

ProductionBatchWorked = var a=SUMMARIZE(ALLSELECTED('Table'),[ProductionBatch],[Shift1])
var b=SUMMARIZE(ALLSELECTED('Table'),[ProductionBatch],[Shift2])
var c=SUMMARIZE(UNION(a,b),'Table'[Shift1],"Distinct",DISTINCTCOUNTNOBLANK('Table'[ProductionBatch]))
return MAXX(FILTER(c,[Shift1] in VALUES('Table 2'[Shift2])),[Distinct])

Output

vxinruzhumsft_0-1691654712146.png

Best Regards!

Yolo Zhu

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

6 REPLIES 6
Ahmedx
Super User
Super User

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

my solution in DAX

https://1drv.ms/u/s!AiUZ0Ws7G26Rigc-Q_c7tkx3fX-1?e=vdm3x6

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.

Hi @Ahmedx / @Dhairya thanks so far, as the users are never happy, how to accomplish this new column?
Thanks

    Desire results 
ProductionBatchProductShift1Shift2NameProductsWorkedProductionBatchWorked
XX01aWadeBrianWade21
XX01bDaveRobertoDave33
XX01cSethRamonSeth43
XX01dBrianWadeBrian32
XX02eRobertoRileyRoberto22
XX02fRamonGilbertRamon33
XX02gJorgeGilbertJorge11
XX02h DanGilbert53
XX02iBrianRamonRiley11
XX02jRobertoDaveDan11
XX02kRamonBrian   
XX03lRamonSeth   
XX03m Dave   
XX03nGilbertRamon   
XX03oGilbertSeth   
XX03pGilbertSeth   



Hi @Aucesar 

You can refer to the following measure

1.Create a table to diaplay the user

2.Then create a measure

ProductionBatchWorked = var a=SUMMARIZE(ALLSELECTED('Table'),[ProductionBatch],[Shift1])
var b=SUMMARIZE(ALLSELECTED('Table'),[ProductionBatch],[Shift2])
var c=SUMMARIZE(UNION(a,b),'Table'[Shift1],"Distinct",DISTINCTCOUNTNOBLANK('Table'[ProductionBatch]))
return MAXX(FILTER(c,[Shift1] in VALUES('Table 2'[Shift2])),[Distinct])

Output

vxinruzhumsft_0-1691654712146.png

Best Regards!

Yolo Zhu

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

 

 

 

Hi @v-xinruzhu-msft , @Ahmedx , @Dhairya  thank you all! Worked like a champ!

Hey @Aucesar 
If the provided solution helps you then please give it a kudo and mark my solution as accepted so that other can find it quickly on facing similar issue. Thank You!

Dhairya
Solution Supplier
Solution Supplier

Hey @Aucesar 
You have to transform your data first please follow the below steps

Input:

Dhairya_0-1691497829691.png


Step1: Open Power Query Editor and unpivot Shift1 and Shift2 columns, and click on close and apply
Output:

Dhairya_2-1691497912432.png


Step2: Now create following measure

S1 = 
CALCULATE(
    COUNTX(TableA,TableA[Product]),
    ALLEXCEPT(TableA,TableA[Value])
)


Step3: Plot your expected columns you will get the following output

Dhairya_3-1691498024165.png

If this helps you then please mark my solution as accepted so that others can find it quickly while facing similar issue. Thank You!

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.