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


@ 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

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.


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

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

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.