Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have this dax, how to sum because the next dax is not working. how to fix.
Solved! Go to Solution.
Hi,
I am not sure how your semantic model looks like, but try something like below if it suits your requirement.
expected result measure: =
VAR TablaCondicional =
ADDCOLUMNS (
FILTER (
ALL ( 'Maestro Libro Diario Balance' ),
AND (
( 'Maestro Libro Diario Balance'[Accounting Date] - 'Maestro Libro Diario Balance'[Batch Created Date] ) < 20,
( 'Maestro Libro Diario Balance'[Accounting Date] - 'Maestro Libro Diario Balance'[Batch Created Date] ) > -20
)
),
"ValorCondicionado",
CALCULATE (
IF (
AND (
SELECTEDVALUE ( 'Maestro Libro Diario Balance'[Accounting Date] )
- SELECTEDVALUE ( 'Maestro Libro Diario Balance'[Batch Created Date] ) < 20,
SELECTEDVALUE ( 'Maestro Libro Diario Balance'[Accounting Date] )
- SELECTEDVALUE ( 'Maestro Libro Diario Balance'[Batch Created Date] ) > -20
),
1,
0
)
)
)
VAR TOTAL =
SUMX ( TablaCondicional, [ValorCondicionado] )
RETURN
TOTAL
Hi @dlagos
It looks as though the RSC and Dia variables are not iterated in row context but calculated based on the filter context, and the additional column 'ValorCondicional' is always equal to the RSC variable and won't vary across the different rows. Also, the Total variable is attempting to sum over 'TablaCondicional' but because of the 'ValorCondicionado' being the same for every row, it is essentially multiplying the same value by the number of rows in 'TablaCondicional.
Try the below and hopefully this will help.
VAR TablaCondicional =
ADDCOLUMNS (
FILTER (
ALL ( 'Maestro Libro Diario Balance' ) ,
AND (
( 'Maestro Libro Diario Balance'[Accounting Date] - 'Maestro Libro Diario Balance'[Batch Created Date] ) < 20 ,
( 'Maestro Libro Diario Balance'[Accounting Date] - 'Maestro Libro Diario Balance'[Batch Created Date] ) > -20
)
) ,
"ValorCondicionado" , IF ( AND ( ( 'Maestro Libro Diario Balance'[Accounting Date] - 'Maestro Libro Diario Balance'[Batch Created Date] ) < 20 , ( 'Maestro Libro Diario Balance'[Accounting Date] - 'Maestro Libro Diario Balance'[Batch Created Date] ) > -20 ) , 1 , 0 )
)
VAR TOTAL = SUMX ( TablaCondicional , [ValorCondicionado] )
RETURN
TOTAL
Hopefully this helps (or at least the logic of it).
Theo 🙂
If I have posted a response that resolves your question, please accept it as a solution to formally close the post.
Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!
Want to connect?www.linkedin.com/in/theoconias
Hi,
I am not sure how your semantic model looks like, but try something like below if it suits your requirement.
expected result measure: =
VAR TablaCondicional =
ADDCOLUMNS (
FILTER (
ALL ( 'Maestro Libro Diario Balance' ),
AND (
( 'Maestro Libro Diario Balance'[Accounting Date] - 'Maestro Libro Diario Balance'[Batch Created Date] ) < 20,
( 'Maestro Libro Diario Balance'[Accounting Date] - 'Maestro Libro Diario Balance'[Batch Created Date] ) > -20
)
),
"ValorCondicionado",
CALCULATE (
IF (
AND (
SELECTEDVALUE ( 'Maestro Libro Diario Balance'[Accounting Date] )
- SELECTEDVALUE ( 'Maestro Libro Diario Balance'[Batch Created Date] ) < 20,
SELECTEDVALUE ( 'Maestro Libro Diario Balance'[Accounting Date] )
- SELECTEDVALUE ( 'Maestro Libro Diario Balance'[Batch Created Date] ) > -20
),
1,
0
)
)
)
VAR TOTAL =
SUMX ( TablaCondicional, [ValorCondicionado] )
RETURN
TOTAL
User | Count |
---|---|
77 | |
75 | |
46 | |
31 | |
28 |
User | Count |
---|---|
99 | |
93 | |
50 | |
49 | |
46 |