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.
Hello,
I want to create a card with last month's sales.
For that, I need a measure that is capable of expressing today "one month ago"
For example, this month's sales is:
This month sales = VAR ThisMonth = MONTH(TODAY()) RETURN CALCULATE('orders'[SalesAmount];'calendar'[month_number]=ThisMonth; 'calendar'[year]=2017)
All time intelligence functions seem to be good to handle columns of date but not scalar values like this case is.
Also, because I'm using a card, there's no "filter context", therefore, I need a volatile function like TODAY.
Thanks!
Solved! Go to Solution.
Hi @webportal,
To consider the month January, how about try this:
Last month sales = VAR LMonth = IF ( MONTH ( TODAY () ) = 1, 12, MONTH ( TODAY () ) - 1 ) VAR YearNum = IF ( MONTH ( TODAY () ) = 1, YEAR ( TODAY () ) - 1, YEAR ( TODAY () ) ) RETURN CALCULATE ( SUM ( 'Previous month sales'[Sales] ), MONTH ( 'calendar'[Date] ) = LMonth, YEAR ( 'calendar'[Date] ) = YearNum )
Regards,
Yuliana Gu
I got round this issue creating two addtonal column:
Hi @webportal,
Based on my test, measure similar to below could return last month sales dynamically.
Last month sales = VAR LMonth = MONTH ( TODAY () ) - 1 RETURN CALCULATE ( SUM ( 'Previous month sales'[Sales] ), MONTH ( 'calendar'[Date] ) = LMonth, YEAR ( 'calendar'[Date] ) = 2017 )
So, what is your concern? As you mentioned, almost time intelligence functions supports date column rather than scalar values like Today(). This is by design, but you could use above workaround.
Best regards,
Yuliana Gu
Hello,
Thanks, will it also work if today is in January?
What will LMonth be then?
Hi @webportal,
To consider the month January, how about try this:
Last month sales = VAR LMonth = IF ( MONTH ( TODAY () ) = 1, 12, MONTH ( TODAY () ) - 1 ) VAR YearNum = IF ( MONTH ( TODAY () ) = 1, YEAR ( TODAY () ) - 1, YEAR ( TODAY () ) ) RETURN CALCULATE ( SUM ( 'Previous month sales'[Sales] ), MONTH ( 'calendar'[Date] ) = LMonth, YEAR ( 'calendar'[Date] ) = YearNum )
Regards,
Yuliana Gu
Hi,
Even if you do not have a Date column in your base data but simple Month and year columns, we can always create a date column from these 2 columns. This will then allow us to use the Date/Time Intelligence functions.
I found out this works:
Last month sales = VAR LastMonth = MONTH(TODAY()-DAY(TODAY()) RETURN CALCULATE('orders'[SalesAmount];'calendar'[month_number]=LastMonth; 'calendar'[year]=2017)
Although probably it's not the most correct syntax..
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
100 | |
80 | |
64 | |
57 |
User | Count |
---|---|
146 | |
110 | |
93 | |
84 | |
67 |