Forum Discussion

jsnrchtr's avatar
jsnrchtr
Regular Visitor
1 year ago
Solved

Help building a calculation or Point me in a Direction

I have a dataflow that is sourcing from an online dataset that updates daily. My dashboard updates daily and pulls in each of probably 4 or 5 different datasets all updating the same way. 

 

I have the below formulas built to calculate different things, but what isn't working is I can't find a way to get the previous day's data. Doing some research is what prompted me to build what I did below but it is not doing what I need it to do. 

 

What I am trying to do is pull in my data and update my visuals. The following day I want to pull in the same data, compare it to the previous day (eventually previous week/month) and then it should adjust the trend arrow accordingly up or down or dash if no change, and change the color. I'd like to eventually graph some data using this process. What I'm trying not to do is pull data daily and store it in a folder to continually reference it if I can help it. 

 

KPI Previous Day Remaining Items =

VAR PrevDayValue =

    CALCULATE(

        [KPI Remaining Items],

        DATEADD('Date'[Date], -1, DAY)

    )

RETURN

    IF(ISBLANK(PrevDayValue), 0, PrevDayValue)

 

KPI Remaining Items =

VAR Result =

    CALCULATE(

        COUNTROWS('MMIS Status Update'),

        'MMIS Status Update'[completion_status] = "Not Completed"

    )

RETURN

    IF(ISBLANK(Result), 0, Result)

 

date table:

Date =

VAR MinDate = CALCULATE(MIN('MMIS Status Update'[update_date]))

VAR MaxDate = CALCULATE(MAX('MMIS Status Update'[update_date]))

RETURN

ADDCOLUMNS(

    CALENDAR(DATE(2020,1,1), DATE(2030,12,31)),

    "Year", YEAR([Date]),

    "Month Number", MONTH([Date]),

    "Month Name", FORMAT([Date], "MMMM"),

    "Year-Month", FORMAT([Date], "YYYY-MM"),

    "Quarter", "Q" & FORMAT([Date], "Q"),

    "Week Number", WEEKNUM([Date], 2), -- 2 - Week starts on Monday

    "Day of Week", FORMAT([Date], "dddd"),

    "Is Weekend", IF(WEEKDAY([Date], 2) >= 6, TRUE(), FALSE())

)

 

Trend Arrow:

KPI Trend Arrow =

SWITCH(

    TRUE(),

    [KPI Remaining Difference] <0,UNICHAR(11165), // Down arrow

    [KPI Remaining Difference] >0,UNICHAR(11167), // Up arrow

    UNICHAR(9644)                                // Dash for no change

)

 

 

Trend Arrow Color:

KPI Trend Arrow Color =

SWITCH(

    TRUE(),

    [KPI Remaining Difference] >0, "Green",

    [KPI Remaining Difference] <0, "Red",

    "Gray"

)

 

KPI Remaining Difference =

[KPI Remaining Items] - [KPI Previous Day Remaining Items]

  • Hi jsnrchtr ,

    Please provide sample PBIX file and show the expected outcome based on the sample data .

     

    Thanks

13 Replies

  • v-dineshya's avatar
    v-dineshya
    Community Support

    Hi jsnrchtr ,

    Thank you for reaching out to the Microsoft Community Forum.

    Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
    Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
    Please show the expected outcome based on the sample data you provided.


    Thank you

  • jsnrchtr's avatar
    jsnrchtr
    Regular Visitor

    In the photo where the gray dashes are, those are the "trend arrow" calculations. The number to the left as it changes, I am wanting the dash to reflect its change. Example: If the previous day was 10, and today it is 9, then I should see a green down arrow. If the number is now 12, I should see a red up arrow. If there is no change, the gray dash should remain. It should reference the previous day's data as the dashboard refreshes.

     

    linNIINMCNmodelserial_numbercompletion_statusreq_compl_end_datecompletion_dateupdate_date
    E05011011234567A1Completed11/9/20248/14/20248/14/2024
    E05011011234567A2Completed7/18/20252/26/20252/26/2025
    E05011011234567A3Completed8/21/202411/15/202211/16/2022
    E05011011234567A4Completed11/9/202410/3/202410/3/2024
    E05011011234567A5Completed7/18/20254/1/20254/23/2025
    E05011011234567A6Completed8/21/20245/20/20215/24/2021
    E05005013217654B7Completed7/18/20254/2/20254/2/2025
    E05004019874321C8N/A2/16/2021 2/17/2021
    E05005013217654B10Not Completed7/18/2025 2/14/2025
    E05004019874321C11Completed11/9/202412/16/202412/16/2024
    E05004019874321C12Completed11/9/20248/26/20249/4/2024
    E05004019874321C13Completed11/9/202411/5/202411/5/2024
    E05004019874321C14Completed2/27/20215/5/20215/5/2021
    E05004019874321C15Completed8/21/202412/13/20211/25/2022
    E05004019874321C16Completed11/9/202410/4/202410/10/2024
    E05004019874321C17N/A2/16/2021 2/17/2021
    E05004019874321C18Completed11/9/202410/17/202410/17/2024
    E05004019874321C19Completed8/21/20246/8/20216/8/2021
    E05004019874321C9Completed8/21/20246/8/2021

    6/8/2021

    • v-dineshya's avatar
      v-dineshya
      Community Support

      Hi jsnrchtr ,
      Thank you for reaching out to the Microsoft Fabric Community forum.

       

      Please follow below steps.

       

      1. please do change your code with below things.

      Make 

      sure your 'Date' table is related to 'MMIS Status Update'[update_date].

      2. Make sure you are filtering the data by a single date (e.g., today), either by a slicer or a measure logic using TODAY().

      3. Current Day KPI Remaining Items

      KPI Remaining Items =
      CALCULATE(
      COUNTROWS('MMIS Status Update'),
      'MMIS Status Update'[completion_status] = "Not Completed"
      )

      4. Previous Day KPI Remaining Items

      KPI Previous Day Remaining Items =
      CALCULATE(
      [KPI Remaining Items],
      DATEADD('Date'[Date], -1, DAY)
      )

      Note: Make sure 'Date'[Date] is marked as a Date table and has a relationship to 'MMIS Status Update'[update_date].

      5.
      KPI Remaining Difference = [KPI Remaining Items] - [KPI Previous Day Remaining Items]

      KPI Trend Arrow =
      SWITCH(
      TRUE(),
      [KPI Remaining Difference] < 0, UNICHAR(11165),
      [KPI Remaining Difference] > 0, UNICHAR(11167),
      UNICHAR(9644)
      )

      KPI Trend Arrow Color =
      SWITCH(
      TRUE(),
      [KPI Remaining Difference] > 0, "Red",
      [KPI Remaining Difference] < 0, "Green",
      "Gray"
      )

       

      If this information is helpful, please “Accept it as a solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
      Thank you.

      • jsnrchtr's avatar
        jsnrchtr
        Regular Visitor

        I had the formulas recommended above already in place initially... the issue that gave me was when the quantity remaining was 0, it returned [blank] instead of "0". I needed it to say 0 instead. 

         

        Can you provide an example how to filter measure logic using today() ? I understand what you're saying, but not sure where to put that reference. 

         

        I have a today() calc to determine if the requirement is overdue: 

        MMIS OVERDUE = IF('MMIS Status Update'[req_compl_end_date].[Date] <=TODAY () , "YES", "NO")
         
        I'm not sure how to apply it for the normal calculations.