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
musicbydannyd
Advocate IV
Advocate IV

DAX MAX for you HACKS :)

Probably a simple answer for you DAX wizards, but I'm stuck on a formula.

I'm importing some Point of Sale data from a SQL server 'view' which joins 2 tables... 1 with a summary values for each receipt and another with the item details. Unfortunately, one of the values I'd like to summarize is only in the summary table and is repeated for each line/row of item detail. I need one value for each unique ticket #. I've tried various combinations of CALULATE, DISTINCT, MAX, FILTER, GROUPBY, etc. with no luck so far... I'm sure I'm missing something obvious. Thanks SO MUCH in advance.

2 ACCEPTED SOLUTIONS

Total Diners = IF(
	HASONEVALUE(ReceiptTable[Receipt #]),
	MAX(ReceiptTable[# of Diners]),
	SUMX(
		VALUES(ReceiptTable[Receipt #]),
		CALCULATE(MAX(ReceiptTable[# of Diners]))
	)
)

Technically only the SUMX part is necessary but this will run faster if you want to show individual receipts with a total at the bottom.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

@musicbydannyd

 

The solution provided by KHorseman should be correct, you can also try with this one.

 

Measure = 
SUMX (
    VALUES ( Table1[Receipt #] ),
    FIRSTNONBLANK ( Table1[# of Diners], Table1[# of Diners] )
)

 

DAX MAX for you HACKS_1.jpg

 

Best Regards,

Herbert

View solution in original post

7 REPLIES 7
musicbydannyd
Advocate IV
Advocate IV

MANY THANKS to @KHorseman and @v-haibl-msft... both solutions worked like a charm!

Greg_Deckler
Super User
Super User

Agreed, would need some sample or example data.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Vvelarde
Community Champion
Community Champion

@musicbydannyd

 

What do you need to do. Show us a sample.

 

Alos do yu need a table with items and the value. A graph?




Lima - Peru

Vvelarde, thanks for the reply. Below is an example (hopefully the table copied over correctly) of the raw data I'm pulling. I'd like to be able to create a measure to sum the "# of Diners" for each unique "Receipt #"... in this case it would be a total of 6, not 24. Hopefully this makes sense.

 

CompanyDiv CodeDivisionOutletReceipt #DateShiftClerkTable ## of DinersPatron CodePatron TypePatron LastPatron FirstAdd1Add2City, StateAdd3Add4ZipGenderBirthDateResignDateTimeLine #Group CodeGroupCat CodeCategoryItem CodeItemItem $Units
1FF&BGrille2300353610/14/20151John Doe   4G1GuestClausSanta1234 Main St                             North Pole, AK                                                          99999M12/25/190001/01/19005:57 PM 1D01Beverages                          ZO01Other DrinksPA005Powerade Berry          21
1FF&BGrille2300353610/14/20151John Doe   4G1GuestClausSanta1234 Main St                             North Pole, AK                                                          99999M12/25/190001/01/19005:57 PM 2B01Beer                               ZB01Beer                          CL002Coors Light Can                    186
1FF&BGrille2300353610/14/20151John Doe   4G1GuestClausSanta1234 Main St                             North Pole, AK                                                          99999M12/25/190001/01/19005:57 PM 3B01Beer                               ZB01Beer                          HN002Heineken Can                       246
1FF&BGrille2300353610/14/20151John Doe   4G1GuestClausSanta1234 Main St                             North Pole, AK                                                          99999M12/25/190001/01/19005:58 PM 4F01Food                               ZS01Snacks                        MM002M&M peanut             11
1FF&BGrille2300353610/14/20151John Doe   4G1GuestClausSanta1234 Main St                             North Pole, AK                                                          99999M12/25/190001/01/19005:58 PM 5F01Food                               ZS01Snacks                        PP001Planters Salted Peanuts      11
2RRetailGift Shop2300353710/14/20151Jane Doe   0NULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULL5:59 PM 1P01ProductsZI02Impulse ItemsDB009Decorative Golf Ball92
2RRetailGift Shop2300353710/14/20151Jane Doe   0NULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULLNULL5:59 PM 2P01ProductsZZ01Misc FoodWG001Wrigley's Spmt 5pk11
8SSpaRelax Spa2300354010/14/20151Joe Blow   0M2MemberTineKris4321 Park Ave                             Anywherein, NY                                                          12345F03/05/195101/01/19006:00 PM 1F10ServicesZS10Spa ServicesF1001Facial 1hr901
1FF&BBar2300354110/14/20151John Doe   2M2MemberRaphoneMike1600 Pennsylvania Ave NW                             Washington, DC                                                          20500M01/01/190001/01/19006:02 PM 1W02WineZW02White WineTB0022 Buck Chuck Pinot Grigio21
1FF&BBar2300354110/14/20151John Doe   2M2MemberRaphoneMike1600 Pennsylvania Ave NW                             Washington, DC                                                          20500M01/01/190001/01/19006:02 PM 2W02WineZR05ChampagneCH021Champipple0.751

 

Thanks again,

DannyD

@musicbydannyd

 

The solution provided by KHorseman should be correct, you can also try with this one.

 

Measure = 
SUMX (
    VALUES ( Table1[Receipt #] ),
    FIRSTNONBLANK ( Table1[# of Diners], Table1[# of Diners] )
)

 

DAX MAX for you HACKS_1.jpg

 

Best Regards,

Herbert

Yeah, MAX is only one of several formulas that would all work identically here. I only stuck with it because it was the first thing @musicbydannyd tried. Since all values for that column are the same, MAX, MIN, AVERAGE, and FIRSTNONBLANK would all return the same value. SUM is the only common aggregator that wouldn't work in this case.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Total Diners = IF(
	HASONEVALUE(ReceiptTable[Receipt #]),
	MAX(ReceiptTable[# of Diners]),
	SUMX(
		VALUES(ReceiptTable[Receipt #]),
		CALCULATE(MAX(ReceiptTable[# of Diners]))
	)
)

Technically only the SUMX part is necessary but this will run faster if you want to show individual receipts with a total at the bottom.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.