please can you let me know why these two measures produce different results? I am obv missing something simple to do with AND and OR. thank you.
measure 1 = CALCULATE (
COUNT ( fct_core[colour] ),
fct_core[type] = 1
|| fct_core[type] = 2
|| fct_core[type] = 3
&& fct_core[colour] = 5
|| fct_core[colour] = 6
|| fct_core[colour] = 7
|| fct_core[colour] = 8
)
measure 2 = CALCULATE (
COUNT ( fct_core[colour] ),
fct_core[type] >= 1
&& fct_core[type] <= 3
&& fct_core[colour] = 5
|| fct_core[colour] = 6
|| fct_core[colour] = 7
|| fct_core[colour] = 8
)
This is an order of operations misunderstanding.
If you put in appropriate parentheses, then these measures should be the same (assuming types only have integer values).
measure 1 =
CALCULATE (
COUNT ( fct_core[colour] ),
(
fct_core[type] = 1 ||
fct_core[type] = 2 ||
fct_core[type] = 3
)
&&
(
fct_core[colour] = 5 ||
fct_core[colour] = 6 ||
fct_core[colour] = 7 ||
fct_core[colour] = 8
)
)
measure 2 =
CALCULATE (
COUNT ( fct_core[colour] ),
(
fct_core[type] >= 1 &&
fct_core[type] <= 3
)
&&
(
fct_core[colour] = 5 ||
fct_core[colour] = 6 ||
fct_core[colour] = 7 ||
fct_core[colour] = 8
)
)
Related
I am having serious performance issue due to this measure. Anyone could help please to have an alternative that might not make the report slow? Just to let you know I am new to dax. thanks :slightly_smiling_face:
Measure_NightMare =
VAR caldate =
SELECTEDVALUE ( 'Calendar'[DayOfWeek] )
RETURN
SWITCH (
TRUE (),
caldate = 6,
CALCULATE (
SUMX ( 'Fact_TBL', 'Fact_TBL'[Col1] )
- SUMX ( 'Fact_TBL', 'Fact_TBL'[Col2] ),
'Fact_TBL'[Value_Col] >= 40
&& 'Fact_TBL'[Value_Col] <= 74
),
caldate = 7,
BLANK ()
,
CALCULATE (
SUMX ( 'Fact_TBL', 'Fact_TBL'[Col1] )
- SUMX ( 'Fact_TBL', 'Fact_TBL'[Col2] ),
'Fact_TBL'[Value_Col] >= 38
&& 'Fact_TBL'[Value_Col] <= 80
)
)
Tried of creating more VARs may be the syntax was incorrect.
Do you have a proper star schema?
You're iterating your fact table multiple times which isn't wise.
Try this.
Measure_SlightlyBetter =
VAR caldate =
SELECTEDVALUE ( 'Calendar'[DayOfWeek] )
RETURN
SWITCH (
TRUE (),
caldate = 6,
CALCULATE (
SUMX ( 'Fact_TBL', 'Fact_TBL'[Col1] - 'Fact_TBL'[Col2]),
'Fact_TBL'[Value_Col] >= 40
&& 'Fact_TBL'[Value_Col] <= 74
),
caldate = 7,
BLANK ()
,
CALCULATE (
SUMX ( 'Fact_TBL', 'Fact_TBL'[Col1] - 'Fact_TBL'[Col2]),
'Fact_TBL'[Value_Col] >= 38
&& 'Fact_TBL'[Value_Col] <= 80
)
)
I'm new at power BI and i've a model with table that call DIVUCHIM_MONE.
I want to get the last [Id] value for the [work_order].
The same [work_order] can be appear several time, the [Id] not.
For exmple:
Id work_order
1 215353
2 215325
3 215325
4 215353
5 215221
6 215231
7 215221
8 215325
9 215353
10 215231
I expected to get:
Id work_order Id_Before
1 215353 0
2 215325 0
3 215325 2
4 215353 1
5 215221 0
6 215231 0
7 215221 5
8 215325 3
9 215353 4
10 215231 6
Please try the following measure
_id =
VAR _currentlyVisibleID =
MAX ( 'Fact'[Id] )
VAR _immediatelyPrecedingByWO =
CALCULATE (
CALCULATE ( MAX ( 'Fact'[Id] ), 'Fact'[Id] < _currentlyVisibleID ),
ALLEXCEPT ( 'Fact', 'Fact'[work_order] )
)
RETURN
_immediatelyPrecedingByWO+0
Edit
Calculated Column
Column =
VAR _currentlyVisibleID =
CALCULATE(MAX ( 'Fact'[Id] ))
VAR _immediatelyPrecedingByWO =
CALCULATE (
CALCULATE ( MAX ( 'Fact'[Id] ), 'Fact'[Id] < _currentlyVisibleID ),
ALLEXCEPT ( 'Fact', 'Fact'[work_order] )
)
RETURN
_immediatelyPrecedingByWO+0
suppose i have 4 parameters eg distance , head count , travellers and country score. what i want to do is if distance<=5 && head count <=20 && travellers <=30 && country score <=1 , then we should get value "VERY LOW".
Try with SWITCH function.
https://dax.guide/switch/
SomeMeasure = SWITCH( TRUE(),
Table[distance]<=5 && Table[head count] <=20 && Table[travellers] <=30 && Table[country score] <=1 , "VERY LOW",
Table[distance <= 10 && Table[Head count] <= 40 && Table[[travellers] <= 60 && Table[country score] <=2 , "LOW",
"NORMAL"
)
I have imported a dataflow from a database into PowerBI. I am trying to write a DAX statement to mimic these constraints on a query I made:
SELECT COUNT(IPID) as theSwitches
FROM MVIEW_E_SWITCH
WHERE (NORMALPOSITIONA = 0 OR NORMALPOSITIONB = 0 OR NORMALPOSITIONC = 0)
AND (FEEDERID2 IS NULL)
Here is my DAX statement:
Open =
( MVIEW_E_SWITCH[NORMALPOSITIONA] = 0
|| MVIEW_E_SWITCH[NORMALPOSITIONB] = 0
|| MVIEW_E_SWITCH[NORMALPOSITIONC] = 0 )
& ( ISBLANK ( MVIEW_E_SWITCH[FEEDERID2] ) )
Dummy Data is below.
IPID NORMALPOSITIONA NORMALPOSITIONB NORMALPOSITIONC FEEDERID2
123141 1 1 1 GC12
145361 0 0 1
096842 0 0 0 BC32
053912 0 0 0
018249 1 1 1
827247 0 1 0 HD32
In DAX, & denotes string concatenation. Use && for logical AND.
Edit: Given that FEEDERID2 is text, I'm guessing your problem is that you have empty strings "" instead of true blanks. Instead of ISBLANK ( MVIEW_E_SWITCH[FEEDERID2] ) try
( ISBLANK ( MVIEW_E_SWITCH[FEEDERID2] ) || MVIEW_E_SWITCH[FEEDERID2] = "" )
or
LEN ( MVIEW_E_SWITCH[FEEDERID2] ) = 0
Try this solution if it helps mark it as the answer.
Create a calculated column with the following DAX:-
Open = IF((Table[NPA] = 0 || Table[NPB] = 0 || Table[NPC] = 0) && ISBLANK(Table[FEEDERID]), TRUE(), FALSE())
This should give you the desired output.
P.S. Column is to check if the FEEDERID is blank or not.
I am trying to sum an amount column based on p_region, statuscode, date range and dollar amount.*
When I try with CALCULATE(SUM()), I cannot get all the clauses that I need.
<£50k =
CALCULATE (
SUM ( tsg_enquiries[tsg_quoteprice_base] ),
tsg_enquiries[statuscode] = 866120000
|| tsg_enquiries[statuscode] = 866120007,
tsg_enquiries[tsg_quoteprice_base] <= 49999
)
The above is missing the date range clause.
tsg_enquiries[createdon] >= 'LTM Live'[xxxBegin] &&`
tsg_enquiries[createdon] <= 'LTM Live'[xxxEnd]`
When I try SUMX(), I cannot evaluate the amount.
£ALL =
SUMX (
FILTER (
tsg_enquiries,
tsg_enquiries[pc_regionno] = 'LTM Live'[pc_regionno]
&& tsg_enquiries[statuscode] = 866120000
|| tsg_enquiries[statuscode] = 866120007
&& tsg_enquiries[statuscode] = 'LTM Live'[pc_regionno]
&& tsg_enquiries[createdon] >= 'LTM Live'[xxxBegin]
&& tsg_enquiries[createdon] <= 'LTM Live'[xxxEnd]
),
tsg_enquiries[tsg_quoteprice_base]
)
The above is missing the amount clause.
tsg_enquiries[tsg_quoteprice_base]<=49999
How can I get my desired result?
If you use complex conditions in filter function, every condition should act on only one column. You could use CalculateTable function, may be. The follows is an example:
SUMX( CALCULATETABLE('InternetSales_USD', 'DateTime'[CalendarYear]=2002)
, [SalesAmount_USD])
If I understand correctly, you're trying to add tsg_enquiries[tsg_quoteprice_base]<=49999 to the criteria in your second query (that uses SUMX)? You can use the AND function, with the initial set of filters as the first argument and tsg_enquiries[tsg_quoteprice_base]<=49999 as the second. While not necessary, you may also want to considered replacing the && and || for readability.
£ALL =
SUMX (
FILTER (
tsg_enquiries,
AND (
tsg_enquiries[pc_regionno] = 'LTM Live'[pc_regionno]
&& tsg_enquiries[statuscode] = 866120000
|| tsg_enquiries[statuscode] = 866120007
&& tsg_enquiries[statuscode] = 'LTM Live'[pc_regionno]
&& tsg_enquiries[createdon] >= 'LTM Live'[xxxBegin]
&& tsg_enquiries[createdon] <= 'LTM Live'[xxxEnd],
tsg_enquiries[tsg_quoteprice_base] <= 49999
)
),
tsg_enquiries[tsg_quoteprice_base]
)