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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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

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!:
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.


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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

Top Kudoed Authors