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
MichaelStrauss
Frequent Visitor

SUM of Columns in a Matrix - Help with DAX

Hi all,

 

I have one fact table with the following data:

 

Each month a forecast is created for the upcoming 12 months. The forecast versions are named 301 (created in January), 302 (Created in February) and so on ..

 

That means that for each month, there are 12 versions that predicted it (some from last year and some in that year). Furthermore the actual sales value of the predicted month is stored in a version called"#". See table below as an example

 

Forecast Version

[Version_Key] in Dax
[Forecast_Creation_Year]Predicted Month_Year

[Month_Year] in Dax
Forecast 
[Forecast_Finance]
Sales of predicted month

[Sales] in Dax
3012021Mar-211.1M 
3022021Mar-210.9M 
3032021Mar-211.11M 
3042020Mar-211.1M 
3052020Mar-210.9M 
3062020Mar-211.11M 
3072020Mar-211.1M 
3082020Mar-210.9M 
3092020Mar-211.11M 
3102020Mar-211.1M 
3112020Mar-210.9M 
3122020Mar-211.11M 
# Mar-21 1M

 

Target: User can set the forecast creation year (single value) and the range of dates (the predicted months - must be in same calendar year meaning months in 2021 only or 2022 only) he would like to see. 

 

I've built a DAX measure for a matrix to show:

Forecast - If a forecast was created within that year (In yellow)

Sales - Otherwise (In Green)

 

MichaelStrauss_0-1664885881825.png

Variables:

VAR SALES = CALCULATE(SUMX('Fact Table',[Sales]),'Fact Table'[Version_key] = "#")

VAR FORECAST_CREATED_AT_CHOSEN_YEAR = CALCULATE(SUMX('Fact Table','Fact Table'[Forecast_Finance]),'Fact Table'[Forecast_Creation_Year] = SELECTEDVALUE('Table'[FORECAST CREATION YEAR]))
-- 'Table' is a table with the parameter of the forecast creation year (I had to make this filter so as to not ruin other stuff)
 
The Measure:

IF(ISBLANK(FORECAST_CREATED_AT_CHOSEN_YEAR),
SALES,
FORECAST_CREATED_AT_CHOSEN_YEAR))

It works great, but I can't figure out a way to put the same logic to the TOTAL column, because it actually loses the filter of the headers (predicted month), and the versions too (as the sales are stored in a special version - "#", without details about creation year)
 
I had encountered the problem of TOTAL column in the past and used 
IF(HASONEVALUE('Fact Table'[Month_Year]), Presented_Measure, .....)
But I can't figure a DAX formula for this case for the TOTAL column
 
 

 

 

5 REPLIES 5
aj1973
Community Champion
Community Champion

Hi @MichaelStrauss 

You need to add a Date Table to your model in order to use Time Intelligence.

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Hi @aj1973 ,
Say I have a date Table, what would be the relation between the tables? I thought about this idea but did not see how it may help me. I have lots of other measures in my dashboard that might be affected by this, that's why I'm looking for a specific solution to my last problem 🙂

what you call a "Fact" table doesn't look like it is! It is more like a manually made table and it is  missing the primary key that would be more like a Date/Time column.

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

That's true, it's not an exact fact table, however it's the data we have available

 

The [Month_Year] column is the date column

Therefore it is not going to work as you want. 

Why don't work directly with the source, do you need help with that?

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

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.

Top Solution Authors
Top Kudoed Authors