Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
OCBB_SFAFPandA
Resolver I
Resolver I

DAX measure to sum up product sales and divide

Hello,

 

I have 2 separate FACTS tables, and do not have a dimension table to link the categories. I tried to manually create the relationship, but it would be many-to-many and would probably slow down the model. How can I create a measure for this?

 

Facts Sales
ProductSales
A100
B150
C110
D500
E300
Facts Qty sold
ProductSold
A10
B15
C20
D50
E10

 

I need to have a measure that sums all the product A (assume the tables are only for 1 day) and divide by Product A quantity sold. 

 

the table I am trying to make is

 ABCDE
Avg saleProd A Sales / Prod B qty  
1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@OCBB_SFAFPandA Not sure if all the information is there but perhaps something like:

Measure = 
  VAR __Product = MAX('Facts Sales'[Product])
  VAR __Sales = AVERAGE('Facts Sales'[Sales])
  VAR __Sold = SUMX(FILTER('Facts Qty sold',[Product] = __Product),[Sold])
RETURN
  DIVIDE(__Sales, __Sold,0)


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@OCBB_SFAFPandA Not sure if all the information is there but perhaps something like:

Measure = 
  VAR __Product = MAX('Facts Sales'[Product])
  VAR __Sales = AVERAGE('Facts Sales'[Sales])
  VAR __Sold = SUMX(FILTER('Facts Qty sold',[Product] = __Product),[Sold])
RETURN
  DIVIDE(__Sales, __Sold,0)


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thanks this works @Greg_Deckler ! needed the sum instead of the avg, so just fixed it. Just so I understand, the reason we don't use sumx( or avgx) for the sales category is because it will be redundant if we are already filtering the product by the quantity sold expression? 

@OCBB_SFAFPandA Right, so if you are using the Product column from the Fact Sales table in your visual, then the rows in that table are already being filtered down to that Product in the context of the visualization. So, no need to use SUMX/AVERAGEX where you include a FILTER clause like is being done in the Sold calculation.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.