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

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.

Reply
Kokkanti
Frequent Visitor

How to divide two years data in to every 6 months once in in power bi

Hi Team,
we have a requirement like we need to show the last two years data in x axis 
here date should calculate like current month to back 6 months.like that we need to show two years data in 4 categories.
Ex: we are in march month now we need to show march 2023 to october 2022.
same like september2022 to April 2022, March 2022 to October 2021,Septemeber 2021 to April 2021.
If we moved to April month dynamically months need to change .
Attached the pic :

Kokkanti_0-1678115037444.png

 



Please help on the issue.
Thank you.

1 ACCEPTED SOLUTION
Kokkanti
Frequent Visitor

@v-yueyunzh-msft  Tqs For U r suggestion .
I have created calculated column like this and it's worked for me

6 Months =
if('Date Table'[Date]<=TODAY()&&'Date Table'[Date]>=DATE(YEAR(TODAY()), MONTH(TODAY())-5, 1),
FORMAT(Today(),"MMM-YYYY")&"-"&FORMAT(DATE(YEAR(TODAY()), MONTH(TODAY())-5, 1),"MMM-YYYY"),

if('Date Table'[Date]<=EOMONTH(DATE(YEAR(TODAY()), MONTH(TODAY())-7, 1),1)&&'Date Table'[Date]>=DATE(YEAR(TODAY()), MONTH(TODAY())-11, 1),
FORMAT(EOMONTH(DATE(YEAR(TODAY()), MONTH(TODAY())-7, 1),1), "MMM-YYYY")&"-"&FORMAT(DATE(YEAR(TODAY()), MONTH(TODAY())-11, 1),"MMM-YYYY"),

if('Date Table'[Date]<=EOMONTH(DATE(YEAR(TODAY()), MONTH(TODAY())-13, 1),1)&&'Date Table'[Date]>=DATE(YEAR(TODAY()), MONTH(TODAY())-17, 1),

FORMAT(EOMONTH(DATE(YEAR(TODAY()), MONTH(TODAY())-13, 1),1), "MMM-YYYY")&"-"&FORMAT(DATE(YEAR(TODAY()), MONTH(TODAY())-17, 1),"MMM-YYYY"),

if('Date Table'[Date]<=EOMONTH(DATE(YEAR(TODAY()), MONTH(TODAY())-19, 1),1)&&'Date Table'[Date]>=DATE(YEAR(TODAY()), MONTH(TODAY())-23, 1),
FORMAT(EOMONTH(DATE(YEAR(TODAY()), MONTH(TODAY())-19, 1),1), "MMM-YYYY")&"-"&FORMAT(DATE(YEAR(TODAY()), MONTH(TODAY())-23, 1),"MMM-YYYY")))))

View solution in original post

2 REPLIES 2
Kokkanti
Frequent Visitor

@v-yueyunzh-msft  Tqs For U r suggestion .
I have created calculated column like this and it's worked for me

6 Months =
if('Date Table'[Date]<=TODAY()&&'Date Table'[Date]>=DATE(YEAR(TODAY()), MONTH(TODAY())-5, 1),
FORMAT(Today(),"MMM-YYYY")&"-"&FORMAT(DATE(YEAR(TODAY()), MONTH(TODAY())-5, 1),"MMM-YYYY"),

if('Date Table'[Date]<=EOMONTH(DATE(YEAR(TODAY()), MONTH(TODAY())-7, 1),1)&&'Date Table'[Date]>=DATE(YEAR(TODAY()), MONTH(TODAY())-11, 1),
FORMAT(EOMONTH(DATE(YEAR(TODAY()), MONTH(TODAY())-7, 1),1), "MMM-YYYY")&"-"&FORMAT(DATE(YEAR(TODAY()), MONTH(TODAY())-11, 1),"MMM-YYYY"),

if('Date Table'[Date]<=EOMONTH(DATE(YEAR(TODAY()), MONTH(TODAY())-13, 1),1)&&'Date Table'[Date]>=DATE(YEAR(TODAY()), MONTH(TODAY())-17, 1),

FORMAT(EOMONTH(DATE(YEAR(TODAY()), MONTH(TODAY())-13, 1),1), "MMM-YYYY")&"-"&FORMAT(DATE(YEAR(TODAY()), MONTH(TODAY())-17, 1),"MMM-YYYY"),

if('Date Table'[Date]<=EOMONTH(DATE(YEAR(TODAY()), MONTH(TODAY())-19, 1),1)&&'Date Table'[Date]>=DATE(YEAR(TODAY()), MONTH(TODAY())-23, 1),
FORMAT(EOMONTH(DATE(YEAR(TODAY()), MONTH(TODAY())-19, 1),1), "MMM-YYYY")&"-"&FORMAT(DATE(YEAR(TODAY()), MONTH(TODAY())-23, 1),"MMM-YYYY")))))
v-yueyunzh-msft
Community Support
Community Support

Hi , @Kokkanti 

According to your description, you want to show the four dimension in the x-axis and it need to dynamic show?

That is, judge based on today's date, and then generate 4 dates and put them on your visual.

If this , i think you can create a calculated table(If you need to put on the x-axis , you need to have a column in the table) as this dimension, you can try to use the TODAY() and EOMONTH  to generate this table .And use measure to show the value in your visual .

For more information, you can refer to :
EOMONTH function (DAX) - DAX | Microsoft Learn

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Kudoed Authors