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
sdukes
Helper I
Helper I

calculate the percent difference between two paychecks

Hi guys! got a question I don't see an answer for...
 
I am trying to figure out how to calculate the percent difference between two paychecks. 
currently I have:
 
Percent Paycheck over Paycheck =

    VAR __PREV_ =
        CALCULATE(
            SUM('Payroll Dollars'[Dollars]),
            DATEADD('DateDAX'[Date].[Date], -14, DAY)
        )
    RETURN
        DIVIDE(SUM('Payroll Dollars'[Dollars]) - __PREV, __PREV)
 
This works if the difference between two paychecks is 14 days. but it isn't always.
 
My question is how can I use the table with the dates in it to define that 14 day range instead of the fixed value?
 

for context = my table may look like this:

1/7/2021

$10

1/21/2021

$12

2/8/2021$9
2/22/2021$14

(in theory, it's every 14 days - but in reality some of the paychecks are bi-monthly meaning the expected pay date is a weekend, and actual pay is the following day, i.e. a 15 day gap)

 

I'm looking to reference the dollar value at previous date value (as date appears in the column)

 

let me know if some further clarification is helpful.

thanks!
1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@sdukes 

is this what you want?

Column = 
var last=maxx(FILTER('Table','Table'[DATE]<EARLIER('Table'[DATE])),'Table'[DATE])
return maxx(FILTER('Table','Table'[DATE]=last),'Table'[VALUE])

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

9 REPLIES 9
ryan_mayu
Super User
Super User

@sdukes 

is this what you want?

Column = 
var last=maxx(FILTER('Table','Table'[DATE]<EARLIER('Table'[DATE])),'Table'[DATE])
return maxx(FILTER('Table','Table'[DATE]=last),'Table'[VALUE])

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you Ryan! that's super helpful.

Not sure I fully understand it but will keep at it.. 

 

Is there any way to make this result be filtered by wither filters or slicers? currently it's a fixed value, but I want it to change on a 'per category' basis

@sdukes 

could you please provide the new sample data and expected output?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@ryan_mayu

 

this is my current data with implementing your solution above:

sdukes_0-1624418516501.png

 

 

but if I filter the right 'Facility' column(using either filter or slicer) to equal 'Be..', the 'days from previous' column keeps the fixed value it has in the row:

 

sdukes_1-1624418668085.png

instead of, for example:

row 1: blank

row 2: jan22-jan8=16

row 3: feb5-jan22 =14


 my goal is to have the facility filter apply to the code you wrote above, and it recreate the column with the current date difference.. 

@sdukes 

since this is a visual table, not sample data. i can just have a try.

measure=

VAR lastdate=calculate(max(date),filter(tallexcept(table,table[facilities]),date<max(date)))

return dollars-calculate(sum(dollars),filter(allexcept(table,table[facilities]),date=lastdate))





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Couldn't figure it out... here's some sample data

 

YearQuarterMonthDay Dollars Facility
2020Qtr 1January3 $    24,708.03Ca
2020Qtr 3August14 $    12,135.85Ca
2020Qtr 3September16 $    26,938.38Be
2020Qtr 4October14 $    23,981.89Be
2020Qtr 4December23 $    31,282.14Be
2020Qtr 4December24 $            64.00Ca
2020Qtr 4December31 $    13,276.39Be
2020Qtr 4December31 $    24,093.37Ca
2021Qtr 1February5 $            96.39Be
2021Qtr 2April1 $          217.60Be
2021Qtr 2April15 $            56.66Be
2020Qtr 3July2 $    29,667.20Ca
2020Qtr 3July31 $    26,305.27Ca
2020Qtr 3August19 $    25,385.21Be
2020Qtr 4October23 $    11,167.20Ca
2020Qtr 4October28 $    22,942.42Be
2021Qtr 1February12 $    14,201.05Ca
2020Qtr 1January17 $    25,138.17Ca
2020Qtr 1January31 $    24,292.56Ca
2020Qtr 1February14 $    24,181.89Ca
2020Qtr 1February28 $    23,609.24Ca
2020Qtr 1March13 $    24,457.29Ca
2020Qtr 1March27 $    26,063.86Ca
2020Qtr 2April10 $    26,385.03Ca
2020Qtr 2April24 $    28,938.79Ca
2020Qtr 2May8 $    29,426.91Ca
2020Qtr 2May22 $    29,613.01Ca
2020Qtr 2June5 $    28,931.67Ca
2020Qtr 2June19 $    28,712.81Ca
2020Qtr 3July17 $    28,813.31Ca
2020Qtr 3August28 $    11,461.98Ca
2020Qtr 3September11 $    11,740.76Ca
2020Qtr 3September25 $    12,402.80Ca
2020Qtr 4October9 $    11,513.55Ca
2020Qtr 4November6 $    11,570.28Ca
2020Qtr 4November20 $    11,619.56Ca
2020Qtr 4December4 $    17,094.54Ca
2020Qtr 4December18 $    20,229.14Ca
2021Qtr 1January15 $    12,959.39Ca
2021Qtr 1January29 $    13,528.41Ca
2021Qtr 1February22 $          265.91Be
2021Qtr 1February26 $    13,383.48Ca
2021Qtr 1March12 $    12,931.95Ca
2021Qtr 1March26 $    12,629.75Ca
2021Qtr 2April9 $    13,202.00Ca
2021Qtr 2April23 $    12,465.71Ca
2021Qtr 2May7 $    13,447.80Ca
2021Qtr 2May21 $    12,533.92Ca

@sdukes 

Pls check the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you Ryan! this was super helpful. 

the following code is my result that gets me per paycheck rate of change based on the report you shared:

Per Period Percentage Change =
VAR LAST=
MAXX(
FILTER(
ALL('Payroll Dollars'),
'Payroll Dollars'[date] < MAX('Payroll Dollars'[date]) && 'Payroll Dollars'[Facility] = MAX('Payroll Dollars'[Facility])),
'Payroll Dollars'[date]
)

VAR LVALUE=
SUMX(
FILTER(
ALL('Payroll Dollars'),
'Payroll Dollars'[date] = LAST && 'Payroll Dollars'[Facility] = MAX('Payroll Dollars'[Facility])),
'Payroll Dollars'[Dollars]
)

VAR DIFF=
IF(
ISBLANK(LVALUE),
BLANK(),
SUM('Payroll Dollars'[Dollars])-LVALUE
)

VAR Result=
IF(
ISFILTERED(
'Payroll Dollars'[Dollar Categories]),
BLANK(),
DIVIDE(
DIFF,
SUM('Payroll Dollars'[Dollars])
)
)
 
RETURN Result


I'm still struggling to understand how the MAX values work in regards to keeping the filter.. 
what if there was another item that I wanted to add as a filter? i.e. [Dollar Categories] which I'm currently returning a blank if filter is applied.. 

How would I be able to add another filter option to my code?
 
thank you again!

@sdukes 

maybe try

&& 'Payroll Dollars'[Facility] = MAX('Payroll Dollars'[Facility])&&XXXX=MAX(XXXX)),





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.