Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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

 

amitchandak
Super User
Super User

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

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

Greg_Deckler
Super User
Super User

@Anonymous - Honestly it seems to me you are going about this all wrong. Seems like you should put your data into a matrix visualization and just make sure that the totals displayed within the hierarchy are correct.

 

So, Company and Date in the Rows hierachy and then a measure that follows the principles of MM3TR&R:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Matrix-Measure-Total-Triple-Threat-Rock-amp-Roll/m-p/411443#M150


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.