Forum Discussion

saska10's avatar
saska10
New Member
9 years ago

how to sum values?

Hi everyone,

 

I'm using Power BI desktop working on a car reporting task, and have been struggling with the following problem for days. I'm quite new to Power BI and have very basic DAX knowledge.

 

Here are the tables (relevant columns):

 

REFUEL

DateTimeRegistration NumberRefuel (l)
2017.02.2810:48AAA00151,11
2017.03.0307:39AAA00140,18
2017.03.0410:03AAA00146,46
2017.03.0909:46AAA00136,45
2017.03.1418:35AAA00137,09
2017.03.1619:53AAA00152,15
2017.03.2109:07AAA00131,62
2017.03.2307:48AAA00145,26
2017.03.2708:48AAA00148,87
2017.04.0216:14AAA00149,06

 

Distance:

 

 

DateTimeRegistration NumberDistance(km)
2017.02.28 AAA001120
2017.02.29 AAA001160
2017.03.03 AAA001230
2017.03.04 AAA001320
2017.03.08 AAA001190
2017.03.09 AAA001270
2017.03.12 AAA001370
2017.03.14 AAA001400
2016.03.16 AAA001280
2017.03.20 AAA001340
2017.03.21 AAA001350
2017.03.22 AAA001230
2017.03.23 AAA001250
2017.03.25 AAA001410
2017.03.27 AAA001370
2017.04.01 AAA001390
2017.04.02 AAA001240

 

I'd like to sum the distance in this way:

refueling on the closest day to the last day of the month --> its the firtst day i want to sum (02.28 - 120 km)

to the refueling on the closest day to the day of the next month --> its the last day I want to sum (04.02 - 240 km)

 

 

 

Could anyone please give me any hint how to achieve this?

 

Thanks!

 

4 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Can you explain why 3.27 is not the day that you want instead of 4.02?

     

    I'm guessing that you would need to have a central date table involved here and relate both refuel and distance tables to it. In theory, you could then create a measure that uses ENDOFMONTH in a context that will achieve what you want.

  • v-huizhn-msft's avatar
    v-huizhn-msft
    Microsoft Employee

    Hi saska10,

    It's difficult to reproduce your scenario based on your description, please list your expected result from the sample data sample. So that we can provide the solution which is close to your requirement. Thanks for understanding.

    Best Regards,
    Angelia

    • saska10's avatar
      saska10
      New Member

      Hi v-huizhn-msft,

       

      I want a result table like this:

       

      DateRegistration NumberDistance
      2017.02.28AAA001120
      2017.02.29AAA001160
      2017.03.03AAA001230
      2017.03.04AAA001320
      2017.03.08AAA001190
      2017.03.09AAA001270
      2017.03.12AAA001370
      2017.03.14AAA001400
      2016.03.16AAA001280
      2017.03.20AAA001340
      2017.03.21AAA001350
      2017.03.22AAA001230
      2017.03.23AAA001250
      2017.03.25AAA001410
      2017.03.27AAA001370
      2017.04.01AAA001390
      2017.04.02AAA001

      240

       

      All in all, the most important thing that the result table containts: from the day of refueling closest to the new month till the next new month's closest day of refueling.

       

      Thank you for your help!

      • v-huizhn-msft's avatar
        v-huizhn-msft
        Microsoft Employee

        Hi saska10,

        For this result table, you can click New table under Modeling on home page, type the following formula.

        result-table=SELECTCOLUMNS(Distance,"Date",Distance[Date],"Registration Number",Distance[Registration Number],"Distiance",Distance[Distance])


        Best Regards,
        Angelia