Forum Discussion
esilva32
7 years agoFrequent Visitor
DAX Calculation
Hello guys I am performing a calculation with DAX on power BI and would like to know if anyone could help me. My data is in table A and the results I want are in table B. Best regards, Thank you ...
- 7 years ago
Hi esilva32
It certainly looks like it would be easier to do this in the query editor. If you do need to do it in DAX, try this. Create a new calculated table:
TableB = VAR _BaseTable = ADDCOLUMNS ( GENERATE ( DISTINCT ( TableA[Id] ); GENERATESERIES ( CALCULATE ( DISTINCT ( TableA[StartDate] ) ); CALCULATE ( DISTINCT ( TableA[EndDate] ) ) ) ); "TempVal"; CALCULATE ( DISTINCT ( TableA[Value] ) ) ) VAR _Dates = DISTINCT ( SELECTCOLUMNS ( _BaseTable; "Date"; [Value] ) ) VAR _ResTable = ADDCOLUMNS ( _Dates; "Total Value"; SUMX ( _BaseTable; IF ( [Value] = [Date]; [TempVal] ) ) ) RETURN _ResTable - 7 years ago
Hello guys
Thank you for your help. @AIB thank you, worked perfectly, thanks for the help.
Regards, Portugal.
- 7 years ago
Minor modification:
TableB = VAR _BaseTable = ADDCOLUMNS ( GENERATE ( DISTINCT ( TableA[Id] ); GENERATESERIES ( CALCULATE ( DISTINCT ( TableA[StartDate] ) ); MIN ( TODAY (); CALCULATE ( DISTINCT ( TableA[EndDate] ) ) ) ) ); "TempVal"; CALCULATE ( DISTINCT ( TableA[Value] ) ) ) VAR _Dates = DISTINCT ( SELECTCOLUMNS ( _BaseTable; "Date"; [Value] ) ) VAR _ResTable = ADDCOLUMNS ( _Dates; "Total Value"; SUMX ( _BaseTable; IF ( [Value] = [Date]; [TempVal] ) ) ) RETURN _ResTable
AlB
6 years agoCommunity Champion
Hi esilva32
To make the requirement a bit clearer, can you please show what the expected resulting table B would be? BAsed on the table A example you provide
Please mark the question solved when done and consider giving kudos if posts are helpful.
Cheers ![]()
esilva32
6 years agoFrequent Visitor
Hello!
The possible result would be what is in the image below.
I need to take only a few fields where the field datahora_
1 is maximum.
Thanks