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
Anonymous
Not applicable

Summing / retrieving values based on Distinct Key

I have two related tables

 

Table A contains a unique key and some qty attached to it, e.g. 

 

_Key                 |    QTY

UniqueKey1    |    5

UniqueKey2   |    10

UniqueKey3    |    1

UniqueKey4   |    3

 

Table B contains a list of incidences of Keys by Date, e.g. 

 

Date               |    _Key

Jan 2018     |    UniqueKey4

Jan 2018     |    UniqueKey3

Jan 2018     |    UniqueKey1

Jan 2018     |    UniqueKey3       *note repeated

Jan 2018     |    UniqueKey1       *note repeated

Feb 2018     |    UniqueKey2      

Feb 2018     |    UniqueKey3

Mar 2018     |    UniqueKey2

 

I need to find out the QTY in use by month, by distinct Key (ignoring repeated entries for the same date period), e,g,

 

Date         |          QTY

Jan 2018     |    9

Feb 2018     |    11

Mar 2018     |    10

 

Help Appreciated!!

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

Here is what you need to, set relationship between both tables on key field.

 

and add following column in Tableb

 

Qty = RELATED(Tablea[Qty])

Unique =  FORMAT(Tableb[Date], "YYYYMMDD") & Tableb[Key]

 

Add following measures in table b

 

Max Qty = MAX(Tableb[Qty])

Qty SUM = SUMX(VALUES(Tableb[Unique]),[Max Qty]) 



Add table visual, drop date from tableb and Qty SUM measure



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

6 REPLIES 6
parry2k
Super User
Super User

Here is what you need to, set relationship between both tables on key field.

 

and add following column in Tableb

 

Qty = RELATED(Tablea[Qty])

Unique =  FORMAT(Tableb[Date], "YYYYMMDD") & Tableb[Key]

 

Add following measures in table b

 

Max Qty = MAX(Tableb[Qty])

Qty SUM = SUMX(VALUES(Tableb[Unique]),[Max Qty]) 



Add table visual, drop date from tableb and Qty SUM measure



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Thanks @parry2k for the reponse but this doesn't work...

 

Appending the Unique key to the date doesn't create a unique field... due to the duplicated rows (see January in the table provided, the same key and date occurs more than once).

 

Perhaps thats really the essence of the problem, how to strip out the duplicates but without losing the additional columns I need.

Dont' get caught into that I called that column "Unique", this field is getting used in SUMX where is working as a unique value.

 

Did you tried what I suggested? It worked on my end.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

I did try it and I thought it didn't work... but it does... my mistake was looking at the wrong level granularity which changed the context.

 

My date in reality has Dates in DDMMYYYY (rather than month as I summarised above) and I need to do the deduplication on the level of the month... so keeping what you wrote and looking at the day level gives the right result, but deduplicating against the day but totalling the month gives a different figure.

 

To get the level of the month I changed the FORMAT for the unique calc column to be '"YYYYMM" and everything works a treat.

 

Thanks a lot for the help!

No worries, I'm glad it worked out for you:)

 

Cheers!!!

P



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi All,

 

I got the same issue. I have 1 table with a lot of repeated values, only qty is unique as below screen

image.png

 

What I want to display is 1 line with sum of qty

image.png

 

I tried to create new table Billed Qty = SUMMARIZE(Billing,Billing[Document Number],"Billing Qty",sum(Billing[Billed Quantity])) but I  just have 1 column from orginal table. How can I get the remaining columns?

Plase help. Thanks very much

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.