Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

New Row With Calculated Values

Hi,

 

So, I'm trying to build a table with the company name, date, the number of accidents (and other variables, but let's simplify) and a calculated formula between the 2 dates I select (for which I added a filter because each month I need to change that).

 

Since I need to calculate the difference, I created a new table and inserted that new row with the symbol "∆" 

 

Table 2 = UNION(VALUES(Sheet1[Date]),ROW("Date","∆"))​

 

and then I used the formula: 

 

 

Measure = 
        Var MaxYear = MAX('Table 2'[Date])
        Var MinYear = MIN('Table 2'[Date])
        Var diff = CALCULATE(SELECTEDVALUE(Sheet1[N accidents]),'Table 2'[Date]=MaxYear)-CALCULATE(SELECTEDVALUE(Sheet1[N accidents]),'Table 2'[Date]=MinYear)
        Var final = (DIVIDE(diff*100,(CALCULATE(SELECTEDVALUE(Sheet1[N accidents]),'Table 2'[Date]=MinYear)),"-"))
return SWITCH(SELECTEDVALUE('Table 2'[Date]),"∆",final,SELECTEDVALUE(Sheet1[N accidents]))

 

So, what I'm looking for is something like this:

 

CompanyDateN accidents
A01/12/20182
A01/12/20194
A
100
B01/12/20180
B01/12/20190
B
-
C01/12/20185
C01/12/20190
C
-

 

Instead, I only get the numbers in front of the dates, and no calculated value or even a line for the ∆.

 

Is it even possible what I'm trying to achieve? Should I make the calculation in excel and be done with it?

Help 😄 

Thanks in advance

 
 

Note: I created a sample PBI file but I don't know how to upload it...

 

4 Replies

  • Anonymous , Not very clear. Can you share sample data and sample output in a table format?

    • Anonymous's avatar
      Anonymous
      Not applicable

      Sample data:

      CompanyDateN accidentsDays off
      A01/01/2017215
      A01/02/2017427
      A01/03/2017427
      A01/04/2017427
      A01/05/2017427
      A01/06/2017427
      A01/07/2017427
      A01/08/2017427
      A01/09/2017427
      A01/10/2017427
      A01/11/2017427
      A01/12/2017427
      A01/01/201800
      A01/02/201800
      A01/03/201800
      A01/04/201800
      A01/05/201800
      A01/06/201800
      A01/07/201800
      A01/08/2018217
      A01/09/2018217
      A01/10/2018217
      A01/11/2018217
      A01/12/2018217
      A01/01/201900
      A01/02/201900
      A01/03/201900
      A01/04/201900
      A01/05/201900
      A01/06/201900
      A01/07/201910
      A01/08/201910
      A01/09/201910
      A01/10/201920
      A01/11/201930
      A01/12/201940
      A01/01/202000
      A01/02/202010
      A01/03/202020
      A01/04/202020
      A01/05/202020
      A01/06/202020
      A01/07/202030
      B01/01/201700
      B01/02/201700
      B01/03/201700
      B01/04/201700
      B01/05/201700
      B01/06/201700
      B01/07/201715
      B01/08/201715
      B01/09/201715
      B01/10/201715
      B01/11/201715
      B01/12/201715
      B01/01/201800
      B01/02/201800
      B01/03/201800
      B01/04/201800
      B01/05/201800
      B01/06/201800
      B01/07/201800
      B01/08/201800
      B01/09/201800
      B01/10/201800
      B01/11/201800
      B01/12/201800
      B01/01/201900
      B01/02/201900
      B01/03/201900
      B01/04/201900
      B01/05/201900
      B01/06/201900
      B01/07/201900
      B01/08/201900
      B01/09/201900
      B01/10/201900
      B01/11/201900
      B01/12/201900
      B01/01/202000
      B01/02/202000
      B01/03/202000
      B01/04/202000
      B01/05/202000
      B01/06/202000
      B01/07/202000
      C01/01/201700
      C01/02/2017112
      C01/03/2017112
      C01/04/2017112
      C01/05/2017112
      C01/06/2017112
      C01/07/2017112
      C01/08/2017112
      C01/09/2017112
      C01/10/2017112
      C01/11/2017112
      C01/12/2017112
      C01/01/201800
      C01/02/201822
      C01/03/2018410
      C01/04/2018517
      C01/05/2018517
      C01/06/2018517
      C01/07/2018517
      C01/08/2018517
      C01/09/2018517
      C01/10/2018517
      C01/11/2018517
      C01/12/2018517
      C01/01/201900
      C01/02/201900
      C01/03/201900
      C01/04/201900
      C01/05/201900
      C01/06/201900
      C01/07/201900
      C01/08/201900
      C01/09/201900
      C01/10/201900
      C01/11/201900
      C01/12/201900
      C01/01/202000
      C01/02/202010
      C01/03/202010
      C01/04/202010
      C01/05/202010
      C01/06/202010
      C01/07/202010

       

      Desired output:

      CompanyDateN accidentsDays off
      A01/12/2018217
      A01/12/201940
      A100-
      B01/12/201800
      B01/12/201900
      B--
      C01/12/2018517
      C01/12/201900
      C--

       

      I think I'm trying to achieve a pretty reasonable thing here... 

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, I did a project similar to your needs. In my scenario company needs to get value diferences between selected dates.My measures is like 3 and 2 of them calculates the min and max of selected date, other one is for getting the difference values by substracting them. Maybe it can light you up 🙂 I pasted my measures below.

     

     

    DatesValueMin = CALCULATE(SUM('ValueTable'[Actuals]),
    DATESBETWEEN( Dates[Date],
    MIN(Dates[Date]) -30,
    MIN(Dates[Date])))
    DatesValueMax= CALCULATE(SUM('ValueTable'[Actual]),
    DATESBETWEEN( Dates[Date],
    MAX(Dates[Date]) -30,
    MAX(Dates[Date])))
    DateDIFF = [DatesValueMax]-[DatesValueMin]

     

     

    After that i build the matrix table visual with DateDIFF and other fact table columns.

     

    Hope it helps you if you have questions feel free to ask.