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

Preparing for a certification exam? Ask exam experts all your questions on May 15th. Register now.

Reply
sree2604
New Member

Need Help with Data Model / DAX

I am working on making a dataset more user friendly / light in size. Data Model along with DAX look very promising and would greatly appreciate any help to achieve the below.  

 

Problem:  I need to calculate Sales per million lives for each product by using the below 2 tables.  I am looking to have one measure for the power pivot which can calculate Sales per million lives at any area hierarcy level (Country / State / District level), problem being few areas which have lives may not have any sales.  So for the Sales per million lives calculation at country level .e.g Country B need to have total lives at 50m including last 2 rows in table 2 ($3000 divided by 50).  This measure needs to aggregate lives for the area selected at any level.  Can we use DAX formulas to create such measure ?  
I could acheive this witha a single measure in power query by adding empty sales rows to make the lives whole for each product but this is essentially doubling the table 1 size for my dataset (shown in the last table below), hoping DAX could achieve this without this workaround
 - Table 1 has Sales by Product details.  This is my primary table which has many other fields & Products but not showing here for simplicity

Sales RepDistrictStateCountryProductSales
AAAYYYState ACountry AProd A$1000
BBBZZZState ACountry AProd A$1000
CCCXXXState BCountry BProd A$1000
CCCWWWState BCountry BProd A$1000
CCCVVVState BCountry BProd A$1000

 

 - Table 2 has Lives at Country / State / DistrictRep level.  the last 2 rows are combinations which do not have any sales but those lives need to be included in Sales per million lives calculation for those respective state / country 

Sales RepDistrictStateCountryLives (in M)
AAAYYYState ACountry A10
BBBZZZState ACountry A10
CCCXXXState BCountry B10
CCCWWWState BCountry B10
CCCVVVState BCountry B10
DDDUUUState BCountry B10
AAAPPPState ACountry B10

 

Current workaround in Power Query: to calculate Sales per Million lives I am currently using power query to add empty sales rows to make lives whole for each product and then created a calculated field in pivot to calculate Sales per million lives.  The single calculated feild does Sales per Million lives calc at any area level 

 

Sales RepDistrictStateCountryProductSalesLives (in M)
AAAYYYState ACountry AProd A$1,00010
BBBZZZState ACountry AProd A$1,00010
CCCXXXState BCountry BProd A$1,00010
CCCWWWState BCountry BProd A$1,00010
CCCVVVState BCountry BProd A$1,00010
  State BCountry BProd A 10
   Country BProd A 10

 

1 ACCEPTED SOLUTION
sanalytics
Super User
Super User

@sree2604 
Please create proper data model rather than only create DAX.. beacuse DAX works on relationship.. Your two tables have different grain so you should have two fact table.. Below is the complete screenshot of your data model

sanalytics_0-1745913645907.png

You need to have a simple star schema

sanalytics_1-1745915484393.png

 

Complete pbix file is attached below.

 

Hope it helps

Regards

sanalytics

 

 

 

 

View solution in original post

4 REPLIES 4
v-menakakota
Community Support
Community Support

Hi @sree2604 ,

Thank you for reaching out to us on the Microsoft Fabric Community Forum.


Thank you @sanalytics  for providing possible solution,that mentioned  separating the data model into two fact tables with shared dimension tables really make a difference. Since the Sales and Lives data are at different grains, trying to force them into one table (like I initially did in Power Query) was increasing the model size unnecessarily.

After restructuring the model (with a proper star schema), calculate Sales per  Million Lives using clean DAX without needing to duplicate rows.

Total Sales := SUM(FactSales[Sales])
Total Lives := SUM(FactLives[Lives (in M)])

Sales per Million Lives :=
DIVIDE([Total Sales], [Total Lives] * 1000000, 0)

If this post was helpful, please give us Kudos and consider marking Accept as solution to assist other members in finding it more easily.

 

sanalytics
Super User
Super User

@sree2604 
Please create proper data model rather than only create DAX.. beacuse DAX works on relationship.. Your two tables have different grain so you should have two fact table.. Below is the complete screenshot of your data model

sanalytics_0-1745913645907.png

You need to have a simple star schema

sanalytics_1-1745915484393.png

 

Complete pbix file is attached below.

 

Hope it helps

Regards

sanalytics

 

 

 

 

worked like a magic!  thank you so much 🙂
appreciate you for sharing the file with the solution, mapping the tables back in the data model and clearly showing how to create the relationships to solve this.

bhanu_gautam
Super User
Super User

@sree2604 First, ensure that you have a relationship between your Sales table (Table 1) and Lives table (Table 2) based on the appropriate columns (e.g., Sales Rep, District, State, Country).

Create a measure to calculate the total lives for the selected area:

Total Lives :=
SUM('Table 2'[Lives (in M)])

 

Create a measure to calculate the total sales:

DAX
Total Lives :=
SUM('Table 2'[Lives (in M)])

 

Create a measure to calculate the total sales:

DAX
Total Sales :=
SUM('Table 1'[Sales])

 

Finally, create a measure to calculate Sales per Million Lives:

DAX
Sales per Million Lives :=
DIVIDE([Total Sales], [Total Lives] * 1000000, 0)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Kudoed Authors