Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hi,
I want to create a table about leave and need a cummulative total.
Actually I already using a measure in here.
And here is the result.
I want in the Annual Leave (Column or Measure) the data max 20. So it will be like this
p.s. the Annual Leave column is the column that I created manually and I expect the result as the Annual Leave column
I already try to create new column with this power query:
Annual Leave Column2 = IF((CALCULATE ( SUM ( Sheet1[Debit/Credit] ), ALL ( Sheet1 ), Sheet1[Date] <= EARLIER ( Sheet1[Date] ) ))>20, 20,CALCULATE ( SUM ( Sheet1[Debit/Credit] ), ALL ( Sheet1 ), Sheet1[Date] <= EARLIER ( Sheet1[Date] ) ))
But the result when it already 20 and there is a -1 in next date it will still count 20 and stuck in 20.
Any help would be appreciate 🙂
Thanks,
Regards,
Connie
Solved! Go to Solution.
Answered by @MarcelBeug in this link.
Thanks a lot for the answer and here is the answer
using power query in advanced editor with this query
let Source = Excel.Workbook(File.Contents("D:\Projects\Internal CRM\Leave Data.xlsx"), null, true), Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type date}, {"Type", type text}, {"Debit/Credit", type number}}), RunningSum = List.Skip(List.Accumulate(#"Changed Type"[#"Debit/Credit"],{0},(sum,value) => sum & {List.Min({12,List.Last(sum)+value})})), TableWithRunningSum = Table.FromColumns(Table.ToColumns(#"Changed Type")&{RunningSum},Value.Type(Table.AddColumn(#"Changed Type","Running Sum", each 0, type number))) in TableWithRunningSum
And thanks for @CahabaData for helping me until I get this answer.
Thank you!
Please help still stuck with this issue.
Any help would be greatly appreciated.
Thanks,
Regards,
Connie
If you create a basic Running Sum column/measure of the Debit/Credit field, it will go above 20. Let that be ok.
Then you can use the IF measure of my first post against this new Running Sum column to create another new column/measure.
Would this be the result you seek?
Hi @CahabaData
Thank you for replying.
If I use the measure, it will be stuck in 20 as you can see my attached picture.
This is in Power BI, as you can see the data will be more than 20. and for Column 2 I using your IF measure the result still stuck in 20 because it read the data is more than 20
But what I the result I need is like this one
As you can see, what I need is the data will be set into 20 so when there is a -1 it will changed into 19 not 20.
And if the data always become 20 and still summing then it's not the result what I seek. And the Annual Leave column is the column that I create manually (not using dax or any calculation) and I need the result as the Annual Leave column. I create it only for comparison if my calculation true or false.
Please let me know if you still don't understand about my requirements. You can download my pbix I already share it in this thread.
Thanks,
Regards,
Connie
this might just work - adding another column with this logic
column 3 = IF( [Debit/Credit]<0 && [column 2] = 20, 20 - [Debit/Credit], [column 2] )
air code....not sure if it will increment correctly in all cases....
Still not work 😞
It become 21 instead.
yeah didn't think that one through
so I think one starts over and relies upon either EARLIER function or possibly the LOOKUPVALUE function and just add the current D/C value to the earlier/prior row Annual Leave value
haven't hashed out the syntax but I think it is going to work
Annual Leave =
VAR currentDate = 'Table1'[Date]
VAR PreDate =
CALCULATE (
LASTDATE ( 'Table1'[Date] ),
FILTER ( 'Table1', 'Table1'[Date] < currentDate )
)
RETURN
IF (
LOOKUPVALUE ( 'Table1'[Value], Table1[Date], PreDate ) + [Debit/Credit] >20, 20,
LOOKUPVALUE ( 'Table1'[Value], Table1[Date], PreDate ) + [Debit/Credit]
) )
by now you've learned to be wary of my air code - but this is a stab at it....... even if this works you may have to wrap another piece of logic to get the initial 16 value....
Hi @CahabaData,
I already tried, and I don't understand what is the Table[Value]? is that I need to create another column that takes a previous value like this one?
And when using this value and your measure the result is like this one
"even if this works you may have to wrap another piece of logic to get the initial 16 value...." And I don't understand why we need to get the initial 16 value?
Thanks,
Regards,
Connie
Annual Leave =
VAR currentDate = 'Table1'[Date]
VAR PreDate =
CALCULATE (
LASTDATE ( 'Table1'[Date] ),
FILTER ( 'Table1', 'Table1'[Date] < currentDate )
)
RETURN
IF (
LOOKUPVALUE ( 'Table1'[Debit/Credit], 'Table1'[Date], PreDate ) + 'Table1'[Debit/Credit] >20, 20,
LOOKUPVALUE ( 'Table1'[Debit/Credit], 'Table1'[Date], PreDate ) + 'Table1'[Debit/Credit]
) )
Hi @CahabaData,
Thank you for taking your time to thinking about the measure, but the result is really weird. Have you try to implement in my pbix file? Since I already shared it and you can download it.
The result is like this one.
Thanks,
Regards,
Connie
Anyone can help with this problem?
because what I think we need the function to refer its own column
yes that is what is needed - will open a new post on this topic....
@Anonymous
Answered by @MarcelBeug in this link.
Thanks a lot for the answer and here is the answer
using power query in advanced editor with this query
let Source = Excel.Workbook(File.Contents("D:\Projects\Internal CRM\Leave Data.xlsx"), null, true), Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type date}, {"Type", type text}, {"Debit/Credit", type number}}), RunningSum = List.Skip(List.Accumulate(#"Changed Type"[#"Debit/Credit"],{0},(sum,value) => sum & {List.Min({12,List.Last(sum)+value})})), TableWithRunningSum = Table.FromColumns(Table.ToColumns(#"Changed Type")&{RunningSum},Value.Type(Table.AddColumn(#"Changed Type","Running Sum", each 0, type number))) in TableWithRunningSum
And thanks for @CahabaData for helping me until I get this answer.
Thank you!
Please try this for a new calculated column in your table:
New Annual Leave = IF([Annual Leave] >20, 20, [Annual Leave])
Hi @CahabaData,
Thanks for replying my question.
I already try your calculation but when it on 20 it will stuck on 20 not going to 19 if there is a -1.
Please check my attached picture.
Thanks,
Regards,
Connie
Hi,
Try this calculated field formula
=MAX(20,CALCULATE(SUM(data[Debit/Credit]),FILTER(Data,Calendar[Date]<=MAX([Date]))))
Ensure that the Date field in your visual is dragged form the calendar table.
Hope this helps.
Hi @Ashish_Mathur,
Am I need to create the calendar table first?
If I'm using the date that already in data the result for the data are taking the data's date. Please refer to my attachment, I'm using the calculation in Column 2.
Hi,
Mine is a calculated field formula (not a calculated column formula). Do you want a calculated column formula?
Please share the link from where i can download your file.
Here is the link:
Actually Column/Measure is ok as long as it's running. I created column just to see the differences.
Thanks
Hi,
Please let me know the exact result which you are expecing in each cell.
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
94 | |
84 | |
83 | |
72 | |
49 |
User | Count |
---|---|
143 | |
130 | |
108 | |
64 | |
55 |