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
toulou
Frequent Visitor

How to create columns to classify dates for "date over date to date" comparison of metrics?

I have a table with very few dimensions but 20+ metrics. I want to visualize the metrics in different ways. A few key scenarios:

 

- Month over Month to Date (e.g. comparing metric A Nov 1-10 2016 with Oct 1-10 2016). Obviously the November date range would always use the latest availble date in the Table within the Month as the MaxDate. 

 

- Month over Month LastYear to Date. Similar scenario as above only that I would compare Nov 1-10 2016 with Nov 1-10 2015. 

 

If I would just do this one or two metrics, it would be acceptable to create measurements for each of the scenario. However, with 20+ metrics this is probably not the route to go (there are also Week over Week, Year over Year or Day over Day (same year and last year) scenarios). 

 

I am wondering if there is a way to create a set of column (probably one each for year, month, week and day) in the table that would classify the inidividual dates.

 

For example:

 

 

DateMetric 1Metric 2Metric 3Metric 4Metric 5Metric 6YtD ClassificationMtD ClassificationWtD ClassificationDay Classification
11/10/2016111111This YearThis MonthThis WeekLast Day
10/10/2016111111This YearThis MonthThis WeekPrevious Day
11/3/2016111111This YearThis MonthLast WeekOther Day
10/9/2016111111This YearPrevious MonthOther WeekOther Day
11/10/2015111111Previous YearMonth Previous YearWeek Previous YearLast Day Previous Year

 

The goal is to create those column values and use them as visual filters and enable them for multiple metrics then within the visual. 

 

Is this the right approach and if to how can it be accomplished? 

 

 

1 ACCEPTED SOLUTION
GilbertQ
Super User
Super User

Hi @toulou, what about using a Period Table, which will make it easier to create the custom periods that you are after?

 

And then you can use your periods to easily create the calculations you require also?

 

http://community.powerbi.com/t5/Data-Stories-Gallery/Create-Dynamic-Periods-for-Fiscal-or-Calendar-D...





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

View solution in original post

5 REPLIES 5
GilbertQ
Super User
Super User

Hi @toulou, what about using a Period Table, which will make it easier to create the custom periods that you are after?

 

And then you can use your periods to easily create the calculations you require also?

 

http://community.powerbi.com/t5/Data-Stories-Gallery/Create-Dynamic-Periods-for-Fiscal-or-Calendar-D...





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

Thank you @GilbertQ. This is good solution. I have looked how you set this up and I going to apply this defining the relative dimensions that I need. 

 

I don't need PeriodType at the moment, however, I figuered this might be an interesting dimension also to indicate certain events in your Period Table. In my case this could be certain News Events for example that I then could also include as an additional insight. As a workflow I could set-up an Excel on SharePoint and have people adding events to a date table. This table could be added to the data model then and become a dimension for report and analysis. 

 

I haven't looked into the metric selector yet but I will. It is a nice way to reduce the number of visuals in a Report.

Hi @toulou, glad that it helped out and also gave you some additional idea's





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!







Power BI Blog

v-qiuyu-msft
Community Support
Community Support

Hi @toulou,

 

If I understand correctly, you want to create calculated columns to return YtD Classification, MtD Classification, WtD Classification and Day Classification, right?

 

From the sample you provided, I guess below DAX should meet your requirement:

 

 

YTD Classification = IF(YEAR('Table1'[Date])=YEAR(TODAY()),"This Year","Previous Year")

 

MtD Classification = Switch(TRUE(),
YEAR('Table1'[Date])=YEAR(TODAY()) && MONTH('Table1'[Date])=MONTH(TODAY()),"This Month",
YEAR('Table1'[Date])=YEAR(TODAY()) && MONTH('Table1'[Date])<MONTH(TODAY()),"Previous Month",
YEAR('Table1'[Date])<YEAR(TODAY()),"Month Previous Year")
WtD Classification = Switch( TRUE(),
WEEKNUM('Table1'[Date],1)=WEEKNUM(TODAY(),1) && YEAR('Table1'[Date])=YEAR(TODAY()),"This Week",
WEEKNUM('Table1'[Date],1)+1=WEEKNUM(TODAY(),1) && YEAR('Table1'[Date])=YEAR(TODAY()),"Last Week",
WEEKNUM('Table1'[Date],1)+1<WEEKNUM(TODAY(),1) && YEAR('Table1'[Date])=YEAR(TODAY()),"Other Week",
YEAR('Table1'[Date])<YEAR(TODAY()),"Week Previous Year")
Day Classification = Switch(TRUE(),
DATEADD('Table1'[Date],1,DAY)=TODAY() ,"Previous Day",
YEAR('Table1'[Date])=YEAR(TODAY()) && 'Table1'[Date]<TODAY(),"Other Day",
YEAR('Table1'[Date])<YEAR(TODAY()),"Last Day Previous Year")

 

q1.PNG

 

If I misunderstand your requirement, please correct me.

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BhaveshPatel
Community Champion
Community Champion

Interesting Question. You probably need to discuss all the details of your data model as there can be many complexities in creating what you desired. Visit www.daxpatterns.com  to know more about these types of calculation.

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.

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.