The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I want to achieve the following logic
I have achieved the GREEN part, but struggling with the RED part.
My Dax is as follows -
=IF(SUM ( 'MasterTbl'[Sett] ) = 1,
SUMX (
(IF (
SUM ( 'MasterTbl'[Sett] ) = 0,
CALCULATE (
SUM ( 'MasterTbl'[Total number of beneficiaries] ),
ALLEXCEPT ( MasterTbl, 'MasterTbl'[Activities and Indicators.Activities] )
) )),
IF
(
VAR _categoryfirst =
CALCULATETABLE (
ADDCOLUMNS (
VALUES ( 'MasterTbl'[List of refugee settlements-Iran.settlements name] ),
"MaxValue",
CALCULATE (
MAX ( 'MasterTbl'[Total number of beneficiaries] ),
ALL ( 'MasterTbl'[Total number of beneficiaries] )
)
),
ALL ( 'MasterTbl'[Total number of beneficiaries] )
)
RETURN
CALCULATE (
MAX ( 'MasterTbl'[Total number of beneficiaries] ),
KEEPFILTERS (
TREATAS (
_categoryfirst,
'MasterTbl'[List of refugee settlements-Iran.settlements name],
'MasterTbl'[Total number of beneficiaries]
)) )) >= SUM('Settlement name'[population]), SUM('Settlement name'[population])),
(
VAR _categoryfirst =
CALCULATETABLE (
ADDCOLUMNS (
VALUES ( 'MasterTbl'[List of refugee settlements-Iran.settlements name] ),
"MaxValue",
CALCULATE (
MAX ( 'MasterTbl'[Total number of beneficiaries] ),
ALL ( 'MasterTbl'[Total number of beneficiaries] )
)
),
ALL ( 'MasterTbl'[Total number of beneficiaries] )
)
RETURN
CALCULATE (
MAX ( 'MasterTbl'[Total number of beneficiaries] ),
KEEPFILTERS (
TREATAS (
_categoryfirst,
'MasterTbl'[List of refugee settlements-Iran.settlements name],
'MasterTbl'[Total number of beneficiaries]
) ) ) ) ),
( IF (
SUM ( 'MasterTbl'[Sett] ) = 0,
CALCULATE (
SUM ( 'MasterTbl'[Total number of beneficiaries] ),
ALLEXCEPT ( MasterTbl, 'MasterTbl'[Activities and Indicators.Activities] )
),
IF
(
(
VAR _categoryfirst =
CALCULATETABLE (
ADDCOLUMNS (
VALUES ( 'MasterTbl'[List of refugee settlements-Iran.settlements name] ),
"MaxValue",
CALCULATE (
MAX ( 'MasterTbl'[Total number of beneficiaries] ),
ALL ( 'MasterTbl'[Total number of beneficiaries] )
)
),
ALL ( 'MasterTbl'[Total number of beneficiaries] )
)
RETURN
CALCULATE (
MAX ( 'MasterTbl'[Total number of beneficiaries] ),
KEEPFILTERS (
TREATAS (
_categoryfirst,
'MasterTbl'[List of refugee settlements-Iran.settlements name],
'MasterTbl'[Total number of beneficiaries]
)
)
)
) >= SUM('Settlement name'[population]), SUM('Settlement name'[population]),
(
VAR _categoryfirst =
CALCULATETABLE (
ADDCOLUMNS (
VALUES ( 'MasterTbl'[List of refugee settlements-Iran.settlements name] ),
"MaxValue",
CALCULATE (
MAX ( 'MasterTbl'[Total number of beneficiaries] ),
ALL ( 'MasterTbl'[Total number of beneficiaries] )
)
),
ALL ( 'MasterTbl'[Total number of beneficiaries] )
)
RETURN
CALCULATE (
MAX ( 'MasterTbl'[Total number of beneficiaries] ),
KEEPFILTERS (
TREATAS (
_categoryfirst,
'MasterTbl'[List of refugee settlements-Iran.settlements name],
'MasterTbl'[Total number of beneficiaries]
) ) ) ) ) )))
Hi @zahirr ,
I can't understand what you mean, please share your sample data and expected output.
Also, I formatted your formula but not sure if it is consistent with yours, please check my sample data and output.
Measure =
VAR _categoryfirst =
CALCULATETABLE (
ADDCOLUMNS (
VALUES ( 'MasterTbl'[List of refugee settlements-Iran.settlements name] ),
"MaxValue",
CALCULATE (
MAX ( 'MasterTbl'[Total number of beneficiaries] ),
ALL ( 'MasterTbl'[Total number of beneficiaries] )
)
),
ALL ( 'MasterTbl'[Total number of beneficiaries] )
)
VAR max_beneficiary =
CALCULATE (
MAX ( 'MasterTbl'[Total number of beneficiaries] ),
KEEPFILTERS (
TREATAS (
_categoryfirst,
'MasterTbl'[List of refugee settlements-Iran.settlements name],
'MasterTbl'[Total number of beneficiaries]
)
)
)
VAR Sum_ =
CALCULATE (
SUM ( 'MasterTbl'[Total number of beneficiaries] ),
ALLEXCEPT ( MasterTbl, 'MasterTbl'[Activities and Indicators.Activities] )
)
RETURN
IF (
SUM ( 'MasterTbl'[Sett] ) = 1,
SUM ( 'MasterTbl'[Total number of beneficiaries] ),
IF (
SUM ( 'MasterTbl'[Sett] ) = 0,
MIN ( max_beneficiary, SUM ( 'Settlement name'[population] ) )
)
)
If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
User | Count |
---|---|
11 | |
9 | |
6 | |
6 | |
5 |
User | Count |
---|---|
22 | |
14 | |
14 | |
9 | |
7 |