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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
mariebel
Frequent Visitor

DAX: Average per group

Hi there, 

Another DAX question from me. 

 

I am trying to show the percentage of potential sales achieved per category. 
I would like the actual sales / potential sales based on sales category. 

My problem is dat the category is in two different tables (one for actuals and one for potentials). This has me completely confused. 

 

Unfortunately I cannot share my file, so I'll do my best to describe the situation below. 


I have one table with sales details, which also includes a details key. In the details table I have the category for the detail key. 
There are several rows for each date/detail key combination as I am tracking sales for multiple stores. 

 

In a separate table I have potential sales per product, with a column CategoryName. 

 

So in summary, the data is as follows: 


AdditionalDetails

DetailKeyCategoryName
1Fruit
2Vegetable
3Meat
4Vegetable
5Fruit

 

Actual Sales

DateDetailKeySales Quantity
01-01-202011
01-01-202022
02-01-202034
03-01-202048
03-01-202059
03-01-202013

 

Potential Sales

DateCategoryNamePotential Sales
01-01-2020Fruit154
01-01-2020Vegetable654
01-01-2020Meat16
02-01-2020Meat48
02-01-2020Vegetable56
02-01-2020Fruit758

 

Thanks in advance for your help!! 



1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

I did this:

 

Measure = 
    VAR __Category = MAX(AdditionalDetails[CategoryName])
    VAR __Date = MAX('ActualSales'[Date])
    VAR __PotentialSales = LOOKUPVALUE(PotentialSales[Potential Sales],PotentialSales[CategoryName],__Category,PotentialSales[Date],__Date)
RETURN
    DIVIDE(SUM(ActualSales[Sales Quantity]),__PotentialSales)

 

PBIX is attached.



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

I did this:

 

Measure = 
    VAR __Category = MAX(AdditionalDetails[CategoryName])
    VAR __Date = MAX('ActualSales'[Date])
    VAR __PotentialSales = LOOKUPVALUE(PotentialSales[Potential Sales],PotentialSales[CategoryName],__Category,PotentialSales[Date],__Date)
RETURN
    DIVIDE(SUM(ActualSales[Sales Quantity]),__PotentialSales)

 

PBIX is attached.



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!

amitchandak
Super User
Super User

@mariebel 

Populate the DetailKey from AdditionalDetails

in column Potential Sales
DetailKey = maxx(filter(AdditionalDetails, AdditionalDetails[CategoryName] ='Potential Sales'[CategoryName]),AdditionalDetails[DetailKey])

 

Now join both table with AdditionalDetails and date dimension and you can use formula

Divide(sum(sales Qty) /sum( potential sales))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.