Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Previous Month only Blank

Hey there,
 
The following code is only returning a blank output for all visuals
 
Previous month Count = CALCULATE( COUNTROWS('CLIENT DATASET') , PREVIOUSMONTH('CLIENT DATASET'[Date]))
 
The Date column is definetely set to the date type format.
 
 
1 ACCEPTED SOLUTION
parry2k
Super User
Super User

The reason I asked because in your sample data one of the numbers (43) has the most recent data up to Oct, the rest is up to Nov and that was the reason for this question. Anyhow here is the measure for the previous month:

 

 

Previous month Count = 
VAR __currentDate = EOMONTH ( MAX ( Sheet1[date] ), -1 )
RETURN 
CALCULATE ( 
    COUNTROWS ( Sheet1 ), 
    DATESBETWEEN ( Sheet1[date], 
    EOMONTH ( __currentDate, -1 ) + 1, __currentDate ) 
)

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

28 REPLIES 28
parry2k
Super User
Super User

The reason I asked because in your sample data one of the numbers (43) has the most recent data up to Oct, the rest is up to Nov and that was the reason for this question. Anyhow here is the measure for the previous month:

 

 

Previous month Count = 
VAR __currentDate = EOMONTH ( MAX ( Sheet1[date] ), -1 )
RETURN 
CALCULATE ( 
    COUNTROWS ( Sheet1 ), 
    DATESBETWEEN ( Sheet1[date], 
    EOMONTH ( __currentDate, -1 ) + 1, __currentDate ) 
)

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

great, thank you that solved my problem

parry2k
Super User
Super User

I think now I got what you are looking for, one more question, let's number 1 has the last transaction date Oct 2020, for this number the current month is Oct 2020 and prev month is Sep 2020 and now another number 2 has the last transaction date Jan 2021, so it's previous month would be Dec 2020. In other words, the current month is relative to the number, not global across all the numbers based on the last date in the table, correct?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

the latest month is consistent across all values. So its always a measure of the current month vs the previous month, doesnt matter if car A was last observed 6 months prior. if its currently jan 2021 and i just got my data in for december 2020, then dec 2020 is the current month, i measure the change for every observation from nov 2020 to dec 2020.

parry2k
Super User
Super User

That's helpful, so the most recent record in the table is deemed as the current month if your data table has the last date let's say Oct 2020 then the current month is Oct 2020 and the previous month is Sep 2020, correct?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Yup thats right, so its all about analysing the relative change. i can only do that if the [previous month] measure i created only counts for the preceeding month (in the example you gave that would be september)

 

 

parry2k
Super User
Super User

if you have 10 months of data and you are not using date or month in your visual, what is the current month in that context? How you define it? 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

The current month is the latest month that I have added data to the table. so if its the 5th of january and ive added data for january 2021, then the current/latest month is january 2021, and the previous month is december 2021.   

parry2k
Super User
Super User

what defines the current month, I think that is what I'm asking. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Anonymous so you will select a month to compare, correct? if there is no month selected, should it return blank() or use the current month. You have to think thru this and explain all of it. I don't like half baked solutions.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

I have created 2 measures:

 

Current Month - provides total count for each value in a column for the current month

previous month - provides total count for each value in a column for the directly preceeding month 

 

Difference: Current month - previous month 

 

Currently the [previous month] measure is just returning the exact same results as if I want to count from the beginning to the end period. That shouldnt be what it does. 

 

parry2k
Super User
Super User

@Anonymous can you put something in excel how you want to see the data, it is critical to understand to provide the solution, when you say a previous month, you can want to see the month or dates on the rows and then compare the count of that period with the previous month, no?

 

This is such a small piece of thing but because of not clear explanation, it is taking way too long, or maybe I'm not getting it.

 

Read this post to get your answer quickly.

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

image.png

 

If you take the above example , imagine the values under the observations column are values that may occur each month a number of times (random). If the current month is october 2020, I want to compare the count for each value for this month to the previous month, with the ultimate goal of creating  a measure of relative change in order of magnitude.

parry2k
Super User
Super User

@Anonymous is this what you are looking for?

 

parry2k_0-1613350882262.png

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

No not quite, the rows should be the individual observations occuring each month (in this case numbers layed out as strings), and then the current month vs the previous month. 

 

The previous month measure is not functioning properly as it is just showing all counts for the entire period.

parry2k
Super User
Super User

@Anonymous received the link, I will take a look.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Anonymous you can share it with everyone or you can share directly with me, my email address is in the footer.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

i have just shared the file 

parry2k
Super User
Super User

@Anonymous this thing is super simple, I cannot make out anything without looking at it. Maybe create a dummy pbix file and share. if you cannot spend time doing that, not sure how I can assist.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

I have created a dummy report and uploaded it to onedrive. How can i allow you to securely access this document?

 

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.