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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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?

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
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
Community Champion
Community Champion

@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



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.