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
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)

@ 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...

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)

@ 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...

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.


@ 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...

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.