Forum Discussion

ArslanManzoor's avatar
ArslanManzoor
Frequent Visitor
5 years ago
Solved

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

 

 

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!

  • Jihwan_Kim's avatar
    Jihwan_Kim
    5 years ago

    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.
     
     
     
     

    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

10 Replies

  • 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.

     

     

    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

    • ArslanManzoor's avatar
      ArslanManzoor
      Frequent Visitor

      Hi Jihwan_Kim 

      Thanks very much for your response!

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

      • Jihwan_Kim's avatar
        Jihwan_Kim
        Super User

        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.

  • 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])

  • 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?

     

    • Jihwan_Kim's avatar
      Jihwan_Kim
      Super User

      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.