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
info-rchitect
New Member

Nested Aggregates of multiple columns and statistical functions

Hi,

 

I have been trying for days to get this measure to work with no luck.  I need to create a measure called 'SOFT_BIN_DESC_PERCENT' that is aggregated using all rows selected by a slicers for MFG_AREA_NAME_ANON, LOT_ID_ANON, SOFT_BIN_DESC_ANON, and BIN_CATEGORY_ANON.  Some background:

 

- The SOFT_BIN_DESC_PERCENT measure is made up of 2 parts: the sum of SOFT_BIN_DESC_COUNT for all selected rows in the table.  the sum of all QTY_IN for each unique LOT_ID_ANON for all selected rows in the table

- There is a 1:1 relationship between LOT_ID_ANON and QTY_IN.  This prevents me from suming it directly in the measure, it needs to only count each QTY_IN for each LOT_ID_ANON once.

- There are 2 weeks in the dataset, the total QTY_IN per week should be 4177 for WEEK 2022W30 and 6696 for WEEK 2022W31

 

Here is a snippet of the data:

WEEKMFG_STEP_NAMELOT_ID_ANONQTY_INMFG_AREA_NAME_ANONSOFT_BIN_DESC_ANONSOFT_BIN_DESC_COUNTBIN_CATEGORY_ANON
2022W31FT1lotid150Facility1softbin931bincat25
2022W31FT1lotid150Facility1softbin1011bincat31
2022W31FT1lotid150Facility1softbin321bincat10
2022W31FT1lotid150Facility1softbin11bincat1
2022W31FT1lotid150Facility1softbin509bincat16
2022W31FT1lotid150Facility1softbin3837bincat15
2022W30FT1lotid1045Facility1softbin1015bincat31
2022W30FT1lotid1045Facility1softbin651bincat20
2022W30FT1lotid1045Facility1softbin621bincat20
2022W30FT1lotid1045Facility1softbin933bincat25
2022W30FT1lotid1045Facility1softbin503bincat16
2022W30FT1lotid1045Facility1softbin3832bincat15
2022W31FT1lotid10095Facility2softbin841bincat21
2022W31FT1lotid10095Facility2softbin932bincat25
2022W31FT1lotid10095Facility2softbin5013bincat16
2022W31FT1lotid10095Facility2softbin3879bincat15
2022W30FT1lotid2450Facility1softbin231bincat5
2022W30FT1lotid2450Facility1softbin151bincat5
2022W30FT1lotid2450Facility1softbin171bincat5
2022W30FT1lotid2450Facility1softbin501bincat16
2022W30FT1lotid2450Facility1softbin251bincat28
2022W30FT1lotid2450Facility1softbin950bincat27
2022W30FT1lotid2450Facility1softbin10bincat1
2022W30FT1lotid2450Facility1softbin222bincat5
2022W30FT1lotid2450Facility1softbin214bincat5
2022W30FT1lotid2450Facility1softbin625bincat20
2022W30FT1lotid2450Facility1softbin169bincat5
2022W30FT1lotid2450Facility1softbin206bincat5
2022W30FT1lotid2450Facility1softbin655bincat20
2022W30FT1lotid2450Facility1softbin13bincat1
2022W30FT1lotid2450Facility1softbin937bincat25
2022W30FT1lotid2450Facility1softbin384bincat15


The correct summary for SOFT_BIN_DESC_PERCENT and BIN_CATEGORY_PERCENT by week for the data above is:

WEEKMFG_STEP_NAMESOFT_BIN_DESC_ANONBIN_CATEGORY_ANONWeeklyQtyInWeeklySoftbinDescCountWeeklyBinCategoryCountWeeklySoftbinDescPercentWeeklyBinCategoryPercent
2022W30FT1softbin1bincat195333.16%3.16%
2022W30FT1softbin15bincat5951241.05%25.26%
2022W30FT1softbin16bincat5959249.47%25.26%
2022W30FT1softbin17bincat5951241.05%25.26%
2022W30FT1softbin20bincat5956246.32%25.26%
2022W30FT1softbin21bincat5954244.21%25.26%
2022W30FT1softbin22bincat5952242.11%25.26%
2022W30FT1softbin23bincat5951241.05%25.26%
2022W30FT1softbin25bincat2895111.05%1.05%
2022W30FT1softbin38bincat1595363637.89%37.89%
2022W30FT1softbin50bincat1695444.21%4.21%
2022W30FT1softbin62bincat20956126.32%12.63%
2022W30FT1softbin65bincat20956126.32%12.63%
2022W30FT1softbin93bincat2595101010.53%10.53%
2022W30FT1softbin95bincat2795000.00%0.00%
2022W30FT1softbin101bincat3195555.26%5.26%
2022W31FT1softbin1bincat1145110.69%0.69%
2022W31FT1softbin32bincat10145110.69%0.69%
2022W31FT1softbin38bincat1514511611680.00%80.00%
2022W31FT1softbin50bincat16145222215.17%15.17%
2022W31FT1softbin84bincat21145110.69%0.69%
2022W31FT1softbin93bincat25145332.07%2.07%
2022W31FT1softbin101bincat31145110.69%0.69%

 

Any help is greatly appreciated.

 

@tylerc  I can't attach a power-BI report which contains the raw data and the correctly summarized data, sent via email.



3 REPLIES 3
info-rchitect
New Member

Hi Jianbo Li,

 

I tried your suggestion but it did not work.  I will post the power-bi report that has the raw data and the correctly summarized data (I used SQL) as reference.

 

thx

v-jianboli-msft
Community Support
Community Support

Hi @info-rchitect ,

 

Based on your description, I have worked out the measure to calculate the sum of SOFT_BIN_DESC_COUNT for all selected rows in the table and the sum of all QTY_IN for each unique LOT_ID_ANON for all selected rows in the table:

_a = CALCULATE(SUM('Table'[SOFT_BIN_DESC_COUNT]),ALLSELECTED('Table'))

_b = SUMX(SUMMARIZE('Table','Table'[LOT_ID_ANON],'Table'[QTY_IN]),[QTY_IN])

Output:

vjianbolimsft_0-1659432086351.png

 

Besides, how to calculate the measure SOFT_BIN_DESC_PERCENT? If it is dividing the two results?

SOFT_BIN_DESC_PERCENT =

var _a = CALCULATE(SUM('Table'[SOFT_BIN_DESC_COUNT]),ALLSELECTED('Table'))

var _b = SUMX(SUMMARIZE('Table','Table'[LOT_ID_ANON],'Table'[QTY_IN]),[QTY_IN])

return _a/_b

Final output:

vjianbolimsft_1-1659432086357.png

 

If this is not what you want, please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.

Refer to:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

 

Best Regards,

Jianbo Li

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

Jianbo Li,

 

Here is the power-BI report with the raw data (power_bi_data) and the summarized data that I made using SQL (power_bi_data_agg_by_week).

https://www.dropbox.com/s/44e6ymz0yadvssk/bin_agg_example.pbix?dl=0

 

Thanks again for the help.

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.