Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more.
Get startedGrow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.
Hi,
I have one field with only the month (1,2,3,...) and I want to get the sum of the previous month.
So I got:
Sales = Sum(SQL[Sales])
Sales1 = Calculate([Sales]; SQL[month]=SQL[month]-1)
This isn't working. Can anyone h
Solved! Go to Solution.
@mikro87 ,
You mentioned only month so I wrote in that way. Try next one:
Sales1 =
VAR __CurrMonth = MAX ( SQL[month] )
VAR __CurrYear = MAX ( SQL[year] )
VAR __PrevMonth = IF ( __CurrMonth > 1, __CurrMonth - 1, 12 )
VAR __YearOfPrevMonth = IF ( __CurrMonth > 1, __CurrYear, __CurrYear - 1 )
RETURN
CALCULATE ( [Sales], SQL[month] = __PrevMonth, SQL[year] = __YearOfPrevMonth )
Regards,
Ruslan Zolotukhin (zoloturu)
BI Engineer at Akvelon Inc. / Kharkiv Power BI User Group Leader / DAX & Power BI Trainer
-------------------------------------------------------------------
Did I answer your question? Mark my post as a solution!
It was useful? Press Thumbs Up!
You are from Ukraine? If yes then welcome to Power BI User Group - KhPUG website. Other country? Check and find proper one - Power BI User Groups
Try
Sales1 =
var _max maxx(SQL,SQL[month])
return
Calculate([Sales]; all(SQL[month]),SQL[month]=_max-1)
But what will you do for year changes ?
Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges
Connect on Linkedin
Hi @mikro87 ,
Try next code:
Sales1 =
VAR __CurrMonth = MAX ( SQL[month] )
VAR __PrevMonth = __CurrMonth - 1
RETURN
CALCULATE ( [Sales]; SQL[month] = __PrevMonth )
Regards,
Ruslan Zolotukhin (zoloturu)
BI Engineer at Akvelon Inc. / Kharkiv Power BI User Group Leader / DAX & Power BI Trainer
-------------------------------------------------------------------
Did I answer your question? Mark my post as a solution!
It was useful? Press Thumbs Up!
You are from Ukraine? If yes then welcome to Power BI User Group - KhPUG website. Other country? Check and find proper one - Power BI User Groups
It works so far.
But now I have year(2018, 2019, ...) too.
How can I compare the previous month also from Dec. to Jan.?
@mikro87 ,
You mentioned only month so I wrote in that way. Try next one:
Sales1 =
VAR __CurrMonth = MAX ( SQL[month] )
VAR __CurrYear = MAX ( SQL[year] )
VAR __PrevMonth = IF ( __CurrMonth > 1, __CurrMonth - 1, 12 )
VAR __YearOfPrevMonth = IF ( __CurrMonth > 1, __CurrYear, __CurrYear - 1 )
RETURN
CALCULATE ( [Sales], SQL[month] = __PrevMonth, SQL[year] = __YearOfPrevMonth )
Regards,
Ruslan Zolotukhin (zoloturu)
BI Engineer at Akvelon Inc. / Kharkiv Power BI User Group Leader / DAX & Power BI Trainer
-------------------------------------------------------------------
Did I answer your question? Mark my post as a solution!
It was useful? Press Thumbs Up!
You are from Ukraine? If yes then welcome to Power BI User Group - KhPUG website. Other country? Check and find proper one - Power BI User Groups
I get a syntax error, row 4 & 5
@mikro87 ,
Do you use comma or semicolon at your formulas? Maybe you need to replace to proper?
Provide a screenshot of an error and a code if that not helps.
Regards,
Ruslan Zolotukhin (zoloturu)
BI Engineer at Akvelon Inc. / Kharkiv Power BI User Group Leader / DAX & Power BI Trainer
-------------------------------------------------------------------
Did I answer your question? Mark my post as a solution!
It was useful? Press Thumbs Up!
You are from Ukraine? If yes then welcome to Power BI User Group - KhPUG website. Other country? Check and find proper one - Power BI User Groups
I needed the semicolon, thanks
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the June 2024 Power BI update to learn about new features.
User | Count |
---|---|
93 | |
86 | |
80 | |
69 | |
68 |
User | Count |
---|---|
226 | |
129 | |
119 | |
83 | |
77 |