Forum Discussion
M-Query for given DAX query
- 6 years ago
Hi Anonymous ,
You use SELECTEDVALUE in the DAX formula, so the output of this formula will be dynamic. If the formula is converted to M-Query, the result will be static. Do you want to use the parameters in the query editing? Could you share your expected output?
If you want to create “Running Totals in Power Query”, here are two ways:
1. Reference this article: Create Running Totals in Power Query
(tbl as table, sumcolumn as text, rowindex as number) => let #"Removed Other Columns" = Table.SelectColumns(tbl,{sumcolumn, "Index"}), #"Filtered Rows" = Table.SelectRows(#"Removed Other Columns", each [Index] <= rowindex), #"Renamed Columns" = Table.RenameColumns(#"Filtered Rows",{{sumcolumn, "Temp"}}), #"Grouped Rows" = Table.Group(#"Renamed Columns", {}, {{"RunningTotal", each List.Sum([Temp]), type number}}), RunningTotal = Record.Field(#"Grouped Rows"{0},"RunningTotal") in RunningTotallet Source = Table, #"Added Custom" = Table.AddColumn(Source, "Running Total", each fnRunningTotal(Source,"Value",[Index])), #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"}) in #"Removed Columns"2. Reference this post: How to do a running Sum by group in Power Query?
(MyTable as table) as table => let Source = Table.Buffer(MyTable), TableType = Value.Type(Table.AddColumn(Source, "Running Sum", each null, type number)), Cumulative = List.Accumulate(Source[Value],{},(cumulative,cost) => cumulative & {List.Last(cumulative, 0) + cost}), AddedRunningSum = Table.FromColumns(Table.ToColumns(Source)&{Cumulative},TableType) in AddedRunningSumHere is a demo, please try it:
Best Regards,
Community Support Team _ Joey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. - 6 years ago
Hi Anonymous
Please see the attached file with the solution, the file includes two Measures as below.
Cumulative Sum of Log = VAR _maxIndex = MAX( 'Table'[Index] ) RETURN CALCULATE( SUM( 'Table'[LogVal] ), ALLSELECTED( 'Table' ), VALUES( 'Table'[Groups] ), 'Table'[Index] <= _maxIndex )and
Exp(N)-1 = VAR _maxIndex = MAX( 'Table'[Index] ) RETURN CALCULATE( ( EXP( SUM( 'Table'[LogVal] ) ) -1 ), ALLSELECTED( 'Table' ), VALUES( 'Table'[Groups] ), 'Table'[Index] <= _maxIndex )Best Regards,
Mariusz
If this post helps, then please consider Accepting it as the solution.
Please feel free to connect with me.
Hi Anonymous
Please see the attached file with the solution, the file includes two Measures as below.
Cumulative Sum of Log =
VAR _maxIndex = MAX( 'Table'[Index] )
RETURN
CALCULATE(
SUM( 'Table'[LogVal] ),
ALLSELECTED( 'Table' ),
VALUES( 'Table'[Groups] ),
'Table'[Index] <= _maxIndex
)
and
Exp(N)-1 =
VAR _maxIndex = MAX( 'Table'[Index] )
RETURN
CALCULATE(
( EXP( SUM( 'Table'[LogVal] ) ) -1 ),
ALLSELECTED( 'Table' ),
VALUES( 'Table'[Groups] ),
'Table'[Index] <= _maxIndex
)Mariusz
If this post helps, then please consider Accepting it as the solution.
Please feel free to connect with me.
THanks for your solution. I have combined both of them in single query and it works.