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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Anonymous
Not applicable

How to get Data from the Last 6 calendar months with date condition

Hi All,

I'm new to powerbi and have tried searching the solution for my problem. I have a table that needs to get the data from the last 6 months but it has condition.
Please help me solve this one.

I need to get the data from the last 6 calendar months or rolling month  with condition

IF Today is March 15, 2020 I should be able to get the data from August 1, 2019 until January 31, 2020
Another example for this one is
IF Today is Feb 27, 2020  I should be able to get the data from August 1, 2019 until January 31, 2020

but  IF Today is March 16, 2020 I should be able to the data from Sep 1, 2019 until  February 29, 2020
basically the data refresh every 16th of the month 

I managed to do this but its wrong.
R6M= if(AND([Today]>15,[Date]=[Month]-7 Else [Date]=[Month]-8






1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

Hope you have a date table

 

Rolling 6 till  = 
var _count = if(day(today())<16,1,2)*-1
return
CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],_count,month)),-6,MONTH))



Rolling 6 till  = 
var _count = (if(day(today())<16,1,2)+6)+-1
return
CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],startOFMONTH(dateadd(Sales[Sales Date],_count,month)),6,MONTH))
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

6 REPLIES 6
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Is this problem sloved? 
If it is sloved, could you kindly accept it as a solution to close this case and help the other members find it more quickly?
If not, please feel free to let me know.
 
Best Regards
Maggie
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create a measure

Measure 2 = CALCULATE(COUNT('Table'[id]),DATESINPERIOD('Table'[date],EOMONTH(TODAY(),-1),-6,MONTH))

Capture2.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Ashish_Mathur
Super User
Super User

Hi,

Your conditions are confusing.  The day of Feb 27 and Mar 16 are both after 15, so why should the range of dates for both these be different?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

Hope you have a date table

 

Rolling 6 till  = 
var _count = if(day(today())<16,1,2)*-1
return
CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],_count,month)),-6,MONTH))



Rolling 6 till  = 
var _count = (if(day(today())<16,1,2)+6)+-1
return
CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],startOFMONTH(dateadd(Sales[Sales Date],_count,month)),6,MONTH))
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

hi @amitchandak,

Yes, I have a date table.
Thank you for replying unfortunately its not working. 
What I need is count this number of data from the rolling 6 months 
MicrosoftTeams-image.png

 

Can you share sample data and sample output. mark me @.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

Check out the October 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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