Forum Discussion
Result in DAX not filtering correctly
I have a table with 2 months of data.
Oct has all data but Nov has projected and real data.
Nov 1 to 13 is real data.
Nov 14 to 30 is projected data.
I want to display in Power BI this sum(rev) for the current month.
In SQL Server the logic would be as follows:
select *
from my_table
where date_eom=(select eomonth(max(date_mtd)) from my_table)
order by 1
In Power BI Desktop, I have 2 measures created.
1) measure1 = EOMONTH( MAX(my_table[date_mtd]),0)
2) measure2 =
CALCULATE(
sum(my_table[rev]),
FILTER(
my_table,
my_table[date_eom]=[measure1]
)
)
No problem with measure1 as it display the end of month date of Nov 30.
However, the problem is that the result shows all rev (YTD: Oct 1 to Nov 13) instead of only the current's month's rev (Nov 1 to Nov 30).
Thanks in advance!
Thanks v-ljerr-msft!
I used your variable suggestion but I also need to use sumx and calculatetable to get the right data.
I believe that if I just use the calculate and then use sum and filter within the calculate funtion, it would still filter out any projected values.
Here's what ended up working for me:
measure2 =
VAR eom = [measure1] RETURN
sumx(
CALCULATETABLE(
my_table,
month(my_table[date_eom])=eom
),
[rev]
)
5 Replies
- pxg08680
Resolver III
If you want your Table visual to have only Current Month data, why don't you try using filter/slicer.
Select the table and in the visual level filter , select the date_daily column and select relative filtering, select last 1 calendar month or last 30 days.
Hope this helps.
- dtran
Helper II
The result will be on a Card as part of a dashboard.
Also, the result will be used for subsequent calculations.
- pxg08680
Resolver III
https://community.powerbi.com/t5/Desktop/sum-values-with-the-last-date-month/td-p/86975
You can see this solution. This seems to be similar to yours. In the link he is trying to find sum for last month, using same you can try for your solution.
- v-ljerr-msft
Microsoft Employee
Hi dtran,
Based on my test, the formula below should work in your scenario. :smileyhappy:
measure2 = VAR eom = [measure1] RETURN CALCULATE ( SUM ( my_table[rev] ), FILTER ( my_table, my_table[date_eom] = eom ) )Regards
- dtran
Helper II
Thanks v-ljerr-msft!
I used your variable suggestion but I also need to use sumx and calculatetable to get the right data.
I believe that if I just use the calculate and then use sum and filter within the calculate funtion, it would still filter out any projected values.
Here's what ended up working for me:
measure2 =
VAR eom = [measure1] RETURN
sumx(
CALCULATETABLE(
my_table,
month(my_table[date_eom])=eom
),
[rev]
)