March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
Hi all,
I'm pretty new to writing DAX-formulas and I'm stuck with solving the following issue. I've been searching for a long time for similar issues, but haven't found the solution that I'm looking for. Some help would be highly appreciated! Due to the sensitivity of my data I'm affraid I can't share my Powerbi file.
Problem: I would like to correct my monthly/yearly/etc. sales per article for the amount of days that stores have been opened. And I would like to be able to filter this for specific stores/countries or specific time periods (days, months, years, etc.). In other words, I'm looking for the (average) sales per month/.../year per store/area/country.
Relevant connected tables (simplified):
- Calendar
- Stores
- Transaction_data (row for every single transaction)
Condition: If the total salesamount (or turnover) > 0 for a certain day & store, that specific store has been opened on that specific day.
What I've tried uptill now:
Sales_activestorecorrection=SUM(Transaction_data[Salesamount])/Transaction_data[Openingdays_Store]
Openingdays_Store= ????
For Openingdays_Store I think I need to use a combination including COUNTROWS(), and the condition SUM(Sales_amount)>0.
Any help is highly appreciated!
After some more testing I found out that the suggested AverageX-formula above is not the solution.
Example: Let's say that 'Product A' was sold 1x in 'Store 1', 2x in 'Store 2' and 0x in 'Store 3' in January 2019. In that case, the average sales per store for Product A in January should be (1+2+0)/3=1.
The suggested formula above doesn't include 'Store 3' because there was no transaction in that store during January 2019. Therefore it calculates the average as (1+2)/2=1,5. In reality Product A was actually available in Store 3 and therefore Store 3 should have been included in the formula.
If you only store amounts > 0 in your Transaction_data (why would you store 0's?), then AVERAGEX on days should be enough.
[Total Sales] = SUM ( Transaction_data[Sales_amount] ) [Daily Sales Average] = averagex( 'Calendar', [Total Sales] )
This is because averagex omits BLANKS.
If, however, you do have 0's, you could do this:
[Daily Sales Average] = averagex( 'Calendar', calculate( [Total Sales], Transaction_data[Sales_amount] <> 0 ) )
But this will not be as fast as the one above. Storing unnecessary data in fact tables is not recommended because it leads to slower DAX and a bigger model's memory consumption. Also, the more columns you have the worse the compression rate of the table.
Best
Darek
Thanks a lot for your help @Anonymous, exactly what I have been looking for!
I only got the (first) formula working once I added CALCULATE and SUM before the sales amount (see below). On the other hand, for turnover it worked only without SUM. Pretty weird, can't explain the difference, but at least my results are correct.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
23 | |
16 | |
12 | |
9 | |
7 |
User | Count |
---|---|
38 | |
32 | |
28 | |
12 | |
11 |