Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Daily total between two dates

Hi everyone - Interesting use case has come up.

As a user, I want to select two dates, so that I can see the Daily Total Spend for each date on the same row. This is not the running total for the date, it is the true spend for the two days.

 

I am OK with getting a daily cost for a single day but how would I get the daily cost for two separate days and get the data in the same table? I would really like this solution to involve a date picker so the user can select any day they want.

 

The category is subscriptions in Azure.

 

What other information do you need?

  • hi  Anonymous 

    For your case, you could use a matrix visual to get it.

    Just drag date field into columns of matrix visual, and for slicer, if you just want to choose two date, you'd better use list for this slicer.

     

    and if you want use range of a slicer(Between), you could create a measure as below to get it:

    Measure = 
    var ascdaterank =RANKX(ALLSELECTED('Table'[Date]),CALCULATE(MAX('Table'[Date])),,ASC)
    var descdaterank =RANKX(ALLSELECTED('Table'[Date]),CALCULATE(MAX('Table'[Date])),,DESC)
    return
    IF(ascdaterank=1||descdaterank=1,CALCULATE(SUM('Table'[Cost])))

     

    Result:

     

    and here is sample pbix file, please try it.

     

    Regards,

    Lin

6 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

    Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

    The most important parts are:
    1. Sample data as text, use the table tool in the editing bar
    2. Expected output from sample data
    3. Explanation in words of how to get from 1. to 2.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you for the advice; I have tried to match your request and please let me know additional requests.

      1. Power BI Usage_Details Table

      Subscription_NameCostYearMonthDay
      Name_12.246436512020May1
      Name_232.38104132020May1
      Name_320.07923052020May1
      Name_44.841154592020May1

       

      2. Desired Result

      SubscriptionNameCostYearMonthDayCost_2Year_2Month_2Day_2
      Name_12.2464365112020May12.246436512020May17
      Name_232.237710442020May132.38104132020May17
      Name_320.090017962020May120.07923052020May17
      Name_44.8811551112020May14.841154592020May17

       

      3. I would like the flexibility of selecting any two dates. I do not want, for example, to select the first date and then a relative second date (i.e., 1 week before, 1 week after).

  • Anonymous , if take a date and put into a slicer, you have range option with a down symbol.

    Same way if you put date in table or row of a matrix or on the axis of visual you can see day-wise data.

     

    The information you have provided is not making the problem clear to me. Can you please explain with an example.

    Appreciate your Kudos.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks - The range of a slicer is a little off; we need to compare the values associated with two dates without worrying about what falls in between them.

       

      • v-lili6-msft's avatar
        v-lili6-msft
        Community Support

        hi  Anonymous 

        For your case, you could use a matrix visual to get it.

        Just drag date field into columns of matrix visual, and for slicer, if you just want to choose two date, you'd better use list for this slicer.

         

        and if you want use range of a slicer(Between), you could create a measure as below to get it:

        Measure = 
        var ascdaterank =RANKX(ALLSELECTED('Table'[Date]),CALCULATE(MAX('Table'[Date])),,ASC)
        var descdaterank =RANKX(ALLSELECTED('Table'[Date]),CALCULATE(MAX('Table'[Date])),,DESC)
        return
        IF(ascdaterank=1||descdaterank=1,CALCULATE(SUM('Table'[Cost])))

         

        Result:

         

        and here is sample pbix file, please try it.

         

        Regards,

        Lin