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

3 month rolling data visual

Hello!

 

Please can someone help with a problem I am having with Power BI. I have 2 tables below (data sources), the first table is showing the time taken to do tasks A and B over a few months, this data is continuously added to through an app. The second table is showing the targets we have for the time taken to do tasks A and B.

 

I would like to create the following visual in Power BI from the 2 tables, where the 'current' column provides the average time over the past month (from date of viewing the report), and the 3 columns on the right automatically roll-over to show the average times for the past 3 months from the date of viewing the report. For example in January it should show data for October, November and December. Today it should show data for February, March, April.

 

I also want to be able to conditionally format each 'cell' under the 'Current' column and each of the rolling month columns, so that the cell turns red if it's above 5% of the target, yellow if within 5% of target (above or below), and green if over 5% below target.

 

Desired output in Power BI

 

ArslanManzoor_0-1620820529791.png

 

Table 1 (Data source)

TaskDateTime taken
A02-Sep-2042
A02-Oct-2045
A04-Sep-2042
B02-Sep-2065
B02-Oct-2064
B04-Sep-2062
B04-Oct-2065
B05-Nov-2056
B06-Nov-2067
B06-Dec-2058
B06-Dec-2058
B09-Nov-2062
B09-Oct-2057
A04-Oct-2038
A05-Nov-2042
A06-Nov-2041
A06-Dec-2042
A06-Dec-2040
A05-Jan-2142
A06-Jan-2141
A07-Jan-2141
B08-Jan-2163
B09-Jan-2162
B10-Jan-2161
A05-Feb-2141
A06-Feb-2138
A07-Feb-2137
B08-Feb-2163
B09-Feb-2158
B10-Feb-2159
A05-Mar-2142
A06-Mar-2141
A07-Mar-2141
B08-Mar-2162
B09-Mar-2162
B10-Mar-2162
A05-Apr-2144
A06-Apr-2141
B07-Apr-2162
B08-Apr-2162
A05-May-2142
A06-May-2142
A07-May-2142
B08-May-2165
B09-May-2161

 

Table 2 (Targets)

 

TaskTarget
A40
B60

 

Thanks very much in advance!

1 ACCEPTED SOLUTION

Hi, @ArslanManzoor 

Please check the below steps.

 

Write a measure something like below.

 

Conditional Format measure =
SWITCH (
TRUE (),
[Time Taken Avg for Visualization]
> 1.05 * SELECTEDVALUE ( Target[Target] ), 1,
[Time Taken Avg for Visualization]
<= 1.05 * SELECTEDVALUE ( Target[Target] )
&& [Time Taken Avg for Visualization]
>= 0.95 * SELECTEDVALUE ( Target[Target] ), 2,
[Time Taken Avg for Visualization]
< 0.95 * SELECTEDVALUE ( Target[Target] ), 3
)
 
Setup like below.
 
Picture2.pngPicture3.png
 
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

10 REPLIES 10
Pricey79
Helper V
Helper V

@Jihwan_Kim Hello, I'm replying on behalf of Arslan. He has said:

 

Great, thanks  , the conditional formatting now works.

 

 

 

However I have just noticed my table columns have reordered into alphabetical order, any way to resolve this? 

 

Also, under each column, the same value is repeated across as per the screenshot attached. How would I fix this please?

Pricey79_0-1621610290002.png

 

Hi, @Pricey79 

Thank you for your feedback.

Please share your sample pbix file's link here, then I can try to look into it to find out the cause of the problem.

Thanks.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Jihwan_Kim
Super User
Super User

Hi, @ArslanManzoor 

Please check the below picture and the sample pbix file's link down below.

All measures are in the sample pbix file.

In order to show "Current" in the column in Matrix Visualization, I suggest creating an Axis table to show it like below.

 

Picture4.png

 

Time Taken Avg for Visualization =
VAR todaymonthyear =
CALCULATE (
MAX ( 'Calendar'[Month & Year] ),
FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] = TODAY () )
)
VAR previousmonthendoftoday =
EOMONTH ( TODAY (), -1 )
VAR fourmonthbeforeenddate =
EOMONTH ( TODAY (), -4 )
RETURN
SWITCH (
TRUE (),
SELECTEDVALUE ( AxisTable[Month & Year] ) = "Current",
CALCULATE (
[Time Taken Avg],
FILTER ( ALL ( 'Calendar' ), 'Calendar'[Month & Year] <> todaymonthyear )
),
MAX ( 'Calendar'[Date] ) <= previousmonthendoftoday
&& MIN ( 'Calendar'[Date] ) > fourmonthbeforeenddate,
CALCULATE (
[Time Taken Avg],
DATESINPERIOD (
'Calendar'[Date],
EOMONTH ( MAX ( 'Calendar'[Date] ), -1 ),
-3,
MONTH
)
)
)
 
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Hi @Jihwan_Kim 

Thanks very much for your response!

How do I create an axis table? is this a custom visual? 

Hi, @ArslanManzoor 

Thank you for your feedback.

It is created manually based on the needs.

If your actual model size is big, you can create it by using the table-creating DAX function. 

If your actual model size is relatively not big, you can create it by excel and import it, Or you can create it in Power Query Editor. When the size is relatively not big, I prefer creating it in Power Query Editor.

Thanks.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Hi @Jihwan_Kim ,

Thank you for your quick response! 

I'm relatively new to Power BI so struggling to implement your DAX formula/axis table approach with my data. Is there a way I can combine the 2 files so I can just feed my data into your visual?

 

I also want to be able to conditionally format each 'cell' under the 'Current' column and each of the rolling month columns, so that the cell turns red if it's above 5% of the target, yellow if within 5% of target (above or below), and green if over 5% below target. Is this possible with the table you created?

 

Thanks again for your help!

Hi, @ArslanManzoor 

I am not sure how your real data model looks like, but in my opinion, if your table 1 and table 2 has the same table structure as above, then, you can open my pbix file and replace the data with yours. If the date range is larger, then you need to fix the calendar table and axis table to include your date range.

If it is OK with you, please share your table1 and table2, then I can try to look into it to come up with a more accurate solution.

Thank you.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Thanks @Jihwan_Kim , I have managed to get the table to work for my data. 

Is there a solution for my conditional formatting question above I can use in this table?

Hi, @ArslanManzoor 

Please check the below steps.

 

Write a measure something like below.

 

Conditional Format measure =
SWITCH (
TRUE (),
[Time Taken Avg for Visualization]
> 1.05 * SELECTEDVALUE ( Target[Target] ), 1,
[Time Taken Avg for Visualization]
<= 1.05 * SELECTEDVALUE ( Target[Target] )
&& [Time Taken Avg for Visualization]
>= 0.95 * SELECTEDVALUE ( Target[Target] ), 2,
[Time Taken Avg for Visualization]
< 0.95 * SELECTEDVALUE ( Target[Target] ), 3
)
 
Setup like below.
 
Picture2.pngPicture3.png
 
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


amitchandak
Super User
Super User

@ArslanManzoor , Create a common task table.  and a date table, use task from the common table 

 

Rolling 3 before 1 = CALCULATE(sum(Table[Time taken]),DATESINPERIOD('Date'[Date ],eomonth(MAX('Date'[Date]),-1),-3,MONTH))

 

target = sum(Target[Target])

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.