I have created a dashboard in PBI using a dataflow from a live database. I am trying to replicate the constraints of a query in DAX and am a little lost on how to get the correct DAX syntax/results.
Below is the query:
SELECT count(IPID) as theSwitches
FROM KUB.MVIEW_E_SWITCH
WHERE (NORMALPOSITIONA = 0 OR NORMALPOSITIONB = 0 OR NORMALPOSITIONC = 0)
AND (FEEDERID <> FEEDERID2)
AND FEEDERID2 is not null
Here is my DAX:
TIE= (MVIEW_E_SWITCH[NORMALPOSITIONA]= 0 ||
MVIEW_E_SWITCH[NORMALPOSITIONB] = 0 ||
MVIEW_E_SWITCH[NORMALPOSITIONC]= 0)
&& (MVIEW_E_SWITCH[FEEDERID] <> MVIEW_E_SWITCH[FEEDERID2])
&& NOT(ISBLANK(MVIEW_E_SWITCH[FEEDERID2]))
Here is some dummy data:
IPID NORMALPOSITIONA NORMALPOSITIONB NORMALPOSITIONC FEEDERID FEEDERID2
123141 1 1 1 GC21 GC12
145361 0 0 1
096842 0 0 0 BC21 BC32
053912 0 0 0
018249 1 1 1
827247 0 1 0 HD32 HD32
I know it is not going to count these, but I wanted to just get a true/false column and only count the true values for my report section of the PBIX.
Is Dax the correct language to perform this, or should I look to use M Code in the Power Query Editor? Any thoughts would be greatly appreciated.
Thanks!
Here is measure:
TIE = COUNTROWS (CALCULATETABLE(Sheet2, Sheet2[NORMALPOSITIONA]= 0 ||
Sheet2[NORMALPOSITIONB] = 0 ||
Sheet2[NORMALPOSITIONC]= 0
&& (Sheet2[FEEDERID] <> Sheet2[FEEDERID2])
&& NOT(ISBLANK(Sheet2[FEEDERID2]))))
Hi please try the following solution if it helps please mark it as the answer.
Create a calculated column with the following DAX:
Open FID2 =
IF (
AND(
(Table[NPA] = 0 || Table[NPB] = 0 || Table[NPC] = 0 )
&& NOT ( ISBLANK ( Table[FEEDERID2] ) ),
Table[FEEDERID] <> Table[FEEDERID2]
),
TRUE (),
FALSE ()
)
Related
Kümülatif Bireysel = IF(
VALUES(HamData[siralama]) >= 1 && VALUES(HamData[siralama]) <= 12
,
CALCULATE(
SUM(Hamdata[Hedef_Tutar]),
FILTER(Hamdata, Hamdata[GroupBuName] = "Bireysel"),
FILTER(Hamdata, Hamdata[Hedef_Tutar] <> 0),
FILTER(ALLSELECTED(HamData), HamData[siralama] <= MAX(HamData[siralama]))
)
,
"-"
)
Using DAX, I want to find the cumulative Sum of the "Hedef_Tutar" column. My table is called "HamData". Actually, I have 4 conditions. Below are my terms.
HamData[Siralama] >= 1
HamData[Siralama] <= 12
HamData[GroupBuName] = "Bireysel"
HamData[Hedef_Tutar] <> 0
I want to get Cumulative total after above conditions are completed. But when I run this DAX, Getting a cumulative sum without applying filters;
HamData[GroupBuName] = "Bireysel"
HamData[Hedef_Tutar] <> 0
How can I get a cumulative total after applying these filters?
Thank you!
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 have 2 dimension tables with no relation between them.
1 is Product Dimension table as
ProdCode | ValidStartDate | ValidEndDate
XX | 2012-01-01| 2016-12-31
XX | 2017-01-01| 2017-12-31
XX | 2018-01-01| 2020-12-31
2nd is Time table
Year | IsCurrent
2012 | 0
2013 | 0
2014 | 0
2015 | 0
2016 | 0
2017 | 0
2018 | 0
2019 | 0
2020 | 1
I need to create a calculated column in Product table to show IsCurrent column from Time Table wrt the year selected.
I tried with CALCULATE but it expects one of the aggregate functions which i can not use because i want to show value in current row context.
for example:
IsCurrent =
CALCULATE(
MAXA('Time'[IsCurrent]),
FILTER(
'Time',
'Time'[Year] >= YEAR(Product[ValidStartDate])
&& 'Time'[Year] <= YEAR(Product[ValidEndDate])
)
)
This always gives me Max value from the range satisfied for example in case of 1st record (2012- 2016) shows 2016 always but I want to show respective current row year from Time table.
Please suggest.
Thank you.
Try this below Measure script-
Measure
IsCurrent =
CALCULATE(
MAXA('Time'[IsCurrent]),
FILTER(
'Time',
'Time'[Year] >= YEAR(MIN(Product[ValidStartDate]))
&& 'Time'[Year] <= YEAR(MIN(Product[ValidEndDate]))
)
)
Custom Column
IsCurrent_column =
var current_start_year = YEAR(Product[ValidStartDate])
var current_end_year = YEAR(Product[ValidEndDate])
RETURN
CALCULATE(
MAXA('time'[IsCurrent]),
FILTER(
'time',
'time'[Year] >= current_start_year
&& 'time'[Year] <= current_end_year
)
)
Here is the output-
Create this below measure-
in_range =
VAR selected_year = SELECTEDVALUE('time'[Year])
RETURN IF(
YEAR(MIN('product'[ValidStartDate])) <= selected_year
&& YEAR(MIN('product'[ValidEndDate])) >= selected_year
,
1,
0
)
This will give you a output as below-
Now you can add a Visual Level filter using this above measure so that the row wonly show when in_range = 1. This filter will only keep your expected rows in the table.
I am attempting to create a column with 0 or 1 column. I have got IF statement to check if today is between start date and end date.
At the moment, I want it to look at the two dates in one table and assign 1 if today is between start and end dates and 0 if not.
I tried below with no luck
Column = IF(AWBPS[START_DTTM] >= today(),1,IF(AWBPS[END_DTTM] <= today (), 0))
or
Column = DATESBETWEEN(today(), AWBPS[START_DTTM],AWBPS[END_DTTM])
If you want to have a column with 0 or 1 then it would be the best if you apply your expression in the query editor. So go to Edit Query > Add Column > Custom Column and enter the following expression:
= if AWBPS[START_DTTM] >= DateTime.Date(DateTime.LocalNow()) and
AWBPS[END_DTTM] <= DateTime.Date(DateTime.LocalNow())
then 1
else 0
You can combine conditions in DAX using the && AND operator.
Column =
IF ( AWBPS[START_DTTM] >= TODAY () && AWBPS[END_DTTM] <= TODAY (), 1, 0 )
I have a requirement like this,
P.No. BR IND SC TD RM CD PD Out - Col - Required
1 B N T 2/1/2011 2/1/2011 5/1/2007 1/1/2007 1
1 B N T 2/1/2011 2/1/2011 5/1/2010 2/1/2011 1
1 B N T 2/1/2011 6/1/2019 5/1/2007 2/1/2011 0
1 B N T 2/1/2011 1/1/2019 5/1/2007 2/1/2011 0
THE Out-Col-Required is what I am trying to do using DAX - Calculated Column.
This is the Logic that it follows,
Filter the Table for the following first in DAX,
BR = B, IND = N, SC = T, TD = RM
Then identify the Min CD date and Max PD date for P.No.
if the diff is less than 30 months, then 1 else 0.
Kindly help me with this.
Thanks.
Out =
VAR PNo = OutCol[P.No.]
VAR filt =
FILTER (
OutCol;
OutCol[P.No.] = PNo
&& OutCol[TD] = OutCol[RM]
&& OutCol[BR] = "B"
&& OutCol[IND] = "N"
&& OutCol[SC] = "T"
)
VAR monthsDiff =
CALCULATE (
DATEDIFF (
MIN ( OutCol[CD] );
MAX ( OutCol[PD] );
MONTH
);
filt
)
RETURN
IF (
OutCol[TD] = OutCol[RM]
&& OutCol[BR] = "B"
&& OutCol[IND] = "N"
&& OutCol[SC] = "T"
&& monthsDiff < 30;
1;
0
)