cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ivamsikrishna
Helper III
Helper III

SameperiodLastyear on categorical access

I am trying to create a combination chart with bars and Line. Bars being current rolling 12 months and line being Sameperiod last month. Everything working fine when I use dates in Xaxis. However my current requirement would be dislay both rolling and sameperiodlastYear based on category in X axis rather date. Please help if this is feasible. I try to create separate measures but not getting result as expected. Below screen capture which I am trying to achieve and sample data. Would like to display categories in Xaxis, rolling 12 months on bars and sameperiodlast year on bars.

 

ivamsikrishna_0-1623675265330.png

Order IDOrder DateCategory
CA-2017-12622112/30/2021Ship Mode
CA-2017-14325912/30/2021Standard Class
CA-2017-11930511/30/2021First Class
CA-2017-11664511/30/2021Second Class
CA-2017-10413611/1/2021Same Day
CA-2017-10413611/1/2021Ship Mode
CA-2017-13163210/31/2021Standard Class
CA-2017-11711410/31/2021First Class
CA-2017-11711410/31/2021Second Class
CA-2017-1280419/1/2021Same Day
CA-2017-1280419/1/2021Ship Mode
CA-2017-1598848/31/2021Standard Class
CA-2017-1598848/31/2021First Class
US-2017-1483627/1/2021Second Class
US-2017-1483627/1/2021Same Day
US-2017-1483627/1/2021Ship Mode
CA-2017-1029466/30/2021Standard Class
US-2017-1028906/30/2021First Class
CA-2017-1316956/30/2021Second Class
CA-2017-1101985/1/2021Same Day
CA-2017-1101985/1/2021Ship Mode
CA-2017-1519114/30/2021Standard Class
CA-2017-1445264/30/2021First Class
CA-2017-1445264/30/2021Second Class
CA-2017-1557123/2/2021Same Day
CA-2017-1241143/2/2021Ship Mode
CA-2017-1019592/28/2021Standard Class
CA-2017-1019592/28/2021First Class
CA-2017-1172122/26/2021Second Class
CA-2017-1517501/1/2021Same Day
CA-2017-1517501/1/2021Ship Mode
CA-2017-16039512/31/2020Standard Class
CA-2017-16039512/31/2020First Class
CA-2017-10020212/31/2020Second Class
CA-2016-10067111/1/2020Same Day
CA-2016-12919611/1/2020Ship Mode
CA-2016-11916510/31/2020Standard Class
CA-2016-14421810/31/2020First Class
US-2016-14225110/31/2020Second Class
CA-2016-14013010/31/2020Same Day
CA-2016-1165269/1/2020Ship Mode
CA-2016-1165269/1/2020Standard Class
CA-2016-1245839/1/2020First Class
CA-2016-1174088/31/2020Second Class
US-2016-1415448/30/2020Same Day
US-2016-1415448/30/2020Ship Mode
US-2016-1264317/1/2020Standard Class
US-2016-1586807/1/2020First Class
CA-2016-1623556/30/2020Second Class
CA-2016-1623556/30/2020Same Day
CA-2016-1355946/30/2020Ship Mode
CA-2016-1015255/1/2020Standard Class
CA-2016-1547884/30/2020First Class
US-2016-1204604/30/2020Second Class
US-2016-1518623/1/2020Same Day
CA-2016-1112832/29/2020Ship Mode
CA-2016-1016232/28/2020Standard Class
CA-2016-1024562/27/2020First Class
CA-2016-1014482/27/2020Second Class
CA-2016-1287062/27/2020Same Day
CA-2016-1536611/30/2020Ship Mode
US-2016-1666601/30/2020Standard Class
US-2016-1666601/30/2020First Class
CA-2016-1149441/30/2020Second Class
CA-2016-1680321/30/2020Same Day
CA-2015-11081412/5/2019Ship Mode
CA-2015-11081412/5/2019Standard Class
CA-2015-14956612/5/2019First Class
CA-2015-14956612/5/2019Second Class
CA-2015-14174011/1/2019Same Day
CA-2015-13145710/31/2019Ship Mode
CA-2015-12225910/31/2019Standard Class
CA-2015-16253710/28/2019First Class
CA-2015-16253710/28/2019Second Class
CA-2015-16253710/28/2019Same Day
CA-2015-13929010/26/2019Ship Mode
CA-2015-15614610/26/2019Standard Class
CA-2015-15614610/26/2019First Class
CA-2015-15656610/1/2019Second Class
CA-2015-1692019/28/2019Same Day
CA-2015-1692019/28/2019Ship Mode
CA-2015-1046269/1/2019Standard Class
CA-2015-1046269/1/2019First Class
CA-2015-1123198/31/2019Second Class
CA-2015-1115148/31/2019Same Day
CA-2015-1115148/31/2019Ship Mode
CA-2015-1533888/1/2019Standard Class
CA-2015-1533888/1/2019First Class
CA-2015-1248917/31/2019Second Class
CA-2015-1248917/31/2019Same Day
CA-2015-1248917/31/2019Ship Mode
CA-2015-1288606/29/2019Standard Class
US-2015-1416846/29/2019First Class
CA-2015-1657996/29/2019Second Class
US-2015-1000696/29/2019Same Day
CA-2015-1249195/31/2019Ship Mode
CA-2015-1249195/31/2019Standard Class
CA-2015-1249195/31/2019First Class
CA-2015-1008185/31/2019Second Class
CA-2015-1008185/31/2019Same Day
CA-2015-1044865/1/2019Ship Mode
CA-2015-1044865/1/2019Standard Class
US-2015-1641754/30/2019First Class
CA-2015-1351744/30/2019Second Class
CA-2015-1037164/30/2019Same Day
CA-2015-1037164/30/2019Ship Mode
CA-2015-1281253/31/2019Standard Class
CA-2015-1334943/1/2019First Class
CA-2015-1335853/1/2019Second Class
CA-2015-1335853/1/2019Same Day
CA-2015-1040523/1/2019Same Day
1 ACCEPTED SOLUTION

Hi Winniz, I was able figure out alternative, calculating max and minimum dates considering Today(), so it always give meset of months. I refer your calculation and updated it a bit and it is working as expected. Appreciate for help. 

 

Krishna.

View solution in original post

7 REPLIES 7
v-kkf-msft
Community Support
Community Support

Hi @ivamsikrishna ,

 

Try the measures like this:

 

Bar = 
CALCULATE( 
    DISTINCTCOUNT('Table'[Order ID]), 
    FILTER(
        'Table', 
        'Table'[Order Date] > EOMONTH( MAXX( ALL('Table'), 'Table'[Order Date] ), -12 )
    )
)
Line = 
var Max_Date = EOMONTH( MAXX( ALL('Table'), 'Table'[Order Date] ), -12 )
var Min_Date = EOMONTH( Max_Date, -12 )
return 
    CALCULATE( 
        DISTINCTCOUNT('Table'[Order ID]), 
        FILTER(
            'Table', 
            'Table'[Order Date] > Min_Date
            && 'Table'[Order Date] <= Max_Date
        )
    )

 

image.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

Hi Winniz,

Thanks for the details, I try to replicate the same how ever in my actual data frame there was a gap in data feed (having said couple of months data is not loaded) and maxdata picking date differently. We must have data for all  months to get this calculation work as expected. Please advise.

 

Thanks,

Krishna.

Hi @ivamsikrishna ,

 

I randomly deleted several months of data, and after testing, I found that the formula still returned the correct result.

 

Do you only want to roll back 12 months with data? for example, the latest date is 2020-12-31 and there is no data in October 2020, then the data from 2019-12-01 to 2020-12-31 will be calculated.

 

Could you please share more error information (e.g. screenshots or PBIX files) ? 

 

 

Best Regards,
Winniz

Yes, we want to roll back 12 month only even if there is data or not for couple of months in between.

 

Thanks,

Krishna.

Hi @ivamsikrishna ,

 

Not clear. Could you please share more information?

 

What is the difference between the calculation results when there are all months and partial months? 

Spoiler

@ivamsikrishna wrote:

how ever in my actual data frame there was a gap in data feed (having said couple of months data is not loaded) and maxdata picking date differently. We must have data for all months to get this calculation work as expected.

What is your model? Could you please share your PBIX file without sensitive date?

 

Best Regards,
Winniz

 

Hi Winniz, I was able figure out alternative, calculating max and minimum dates considering Today(), so it always give meset of months. I refer your calculation and updated it a bit and it is working as expected. Appreciate for help. 

 

Krishna.

View solution in original post

Hi @ivamsikrishna ,

 

If it has solved, could you please mark your reply as the solution to help the other members find it more quickly?

 

Best Regards,
Winniz

 

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Urdu Hindi D365 Bootcamp 768x460.png

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors