Forum Discussion
Help with DAX query
Hello Team,
I was trying to calculate a Card value using a DAX query. I have a set of data where the DAX formula should perform like
sample data :
| Dimension | Year | Month | Total |
| Actuals | CFY20 | Jul | 4950 |
| Forecast | CFY20 | Aug | 867.5 |
| Actuals | CFY20 | Sep | 34149.5 |
| Actuals | CFY20 | Oct | 17542.2 |
| Actuals | CFY20 | Nov | 112.33 |
| Forecast | CFY21 | Dec | 83.17 |
| Actuals | CFY20 | Jan | 18127.8 |
| Actuals | CFY20 | Feb | 15424.5 |
| Actuals | CFY20 | Mar | 0 |
| Forecast | CFY20 | Apr | -815.86 |
| Forecast | CFY21 | May | 0 |
| Forecast | CFY21 | Jun | -210 |
| Actuals | CFY21 | Jul | 420 |
| Actuals | CFY21 | Aug | 39979 |
| Forecast | CFY21 | Sep | 10047.1 |
| Forecast | CFY21 | Oct | 19138.3 |
| Forecast | CFY21 | Nov | -4672.5 |
| Forecast | CFY21 | Dec | -5185 |
| Actuals | CFY20 | Jan | -196 |
| Actuals | CFY20 | Feb | 0 |
3 Replies
- amitchandak
Super User
swathy429 , if you have date, with date and time intelligence you can have
Month vs month
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-3,MONTH))
Rolling 3 till last 1 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],Startofmonth(dateadd(Sales[Sales Date],-1,month)),3,MONTH))
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.
- swathy429Regular Visitor
Thanks for the reply amitchandak ,
I dont have any dates in the data as you see in the sample data that's all column I Have
- AnonymousNot applicable
Hello @swathy429 ,
Since you do not have any date columns in the table, you will need to create the fym column as below screenshot shown.
fym = FORMAT(DATEVALUE(20&RIGHT('Table'[Year],2)&"-"&'Table'[Month]),"YYYYMM")Part One: SUM(Prev 3 months Actual value)
Measure = CALCULATE(SUM('Table'[Total]),FILTER('Table','Table'[fym]>=FORMAT(EDATE(TODAY(),-3),"YYYYMM")&&'Table'[fym]<FORMAT(TODAY(),"YYYYMM")&&'Table'[Dimension]="Actuals"))Part Two: (largest foreCast value of the month Curent OR actual value)
Measure 2 = var sum_total = CALCULATE(SUM('Table'[Total]),ALLEXCEPT('Table','Table'[Dimension],'Table'[fym])) return MAXX(ALLEXCEPT('Table','Table'[fym]),sum_total)And the third part of your formula is the part I don't quite understand. Can you share more information?
The current result would be something like below.
Best regards
Jay