CONCATENATEX Inside IN Operator POWER BI - powerbi

I'm having a problem testing a POWER BI Measure. I'm trying to concatenate all the selected value in my splicer and want to use it as a values for my IN operator. My code looks like this.
var concats = CONCATENATEX (VALUES( 'Year'[Year] ) , """" & [Year] & """" , ", ")
return
CALCULATE(
COUNTA('End Life'[Category]),
'End Life'[EOLYear] IN { concats }
)
If I will try to manual input say for sample: "2021","2022", it will work but if the Concatenatex result it would not work.
This code always results to blank, I am doing it wrong or I am missing something?
Please do help me with it.
Thanks.

Related

NOT IN Dax equivalent

still very new to DAX and hate it so far. where is the logic?
I have an expression below that creates data for a column based on if the data meets the criteria. What I have is a WORKING example of the opposite of what I'm trying to accomplish. I really, really want to be able to type "NOT IN" but it seems like that is not an option in DAX syntax. So basically, how do I EXCLUDE these values?
Column =
IF ( MMP_Dashboards_WMH_PBI[Revenue_Center] IN {"FillRate","CancelRt","NoShowRt","ExamRt"}, MMP_Dashboards_WMH_PBI[NewUnits] )
Would love for THIS to work:
Column =
IF ( MMP_Dashboards_WMH_PBI[Revenue_Center] NOT IN {"FillRate","CancelRt","NoShowRt","ExamRt"}, MMP_Dashboards_WMH_PBI[NewUnits] )
Try this:
IF ( NOT ( MMP_Dashboards_WMH_PBI[Revenue_Center] IN {"FillRate","CancelRt","NoShowRt","ExamRt"} ), MMP_Dashboards_WMH_PBI[NewUnits] )

Issue in applying filter in Power BI Desktop DAX forumla

I am facing an issue while working with power bi desktop. i am having an csv file as a datasource and i am having a column with multiple values, say "abc, def", "jkl" "zyz" etc.
Here, i need to generate a report with rows having showing "def" & "jkl" .
How to filter this using DAX Filter command. i wanted to fetch, filter only two values CTF& EVE in the Power BI report.
I tried with creating a calculated column and applied the below code but it didnt work:
Columnjkl = FILTER((Table1,OR(Table1[mycolumn1] == "def" || "jkl"))
filter-2cols-ctf-eve-
You need to read how DAX syntax is written, check this page to see how you use the FILTER function (FILTER) and this for how to use the OR function (OR)
Basically, Filter returns a table, so using it to calculate a column will not work. However, by implementing the FILTER function inside a CALCULATE you can change/modify what the main argument of CALCULATE will evaluate. The calculation flow in DAX is such that first the filter argument is evaluated and then the aggregation (or what ever) is evaluated. Example:
NumberOfRowsWithABC =
CALCULATE =
COUNTROWS('Table1'),
FILTER(
'Table1',
'table1[mycolumn1] = "abc"
)
)
First the FILTER function only selects the rows in 'Table1' where [mycolumn1] has the text value abc. Then it passes this reduced table to the COUNTROW function, which counts the number of rows in the table passed to it.
The syntax for the OR function is wrong. This is how you should write it:
OR(
'Table1'[mycolumn1] = "def",
'Table1'[mycolumn1] = "jkl"
)
Perhaps a better way of writing this OR function is using the in-command as the filter argument of the calculate function:
NumberOfRowsWith_def_and_jkl =
CALCULATE(
COUNTROWS('Table1'),
'Table1'[mycolumn1] in {"def", "jkl"}
)
But as Gangula wrote, you don't need to filter 'Table1' using the FILTER function, it can all be done visually on the dashboard.

DAX - Measure Works when used against the required dimension but not alone in a card visual

I have a requirement like this :-
Role_Skills =
CONCATENATEX (
FILTER (Jobs, Jobs[Role] = SELECTEDVALUE(Jobs[Role])),
Jobs[Skills],
","
)
This Measure works when I put it on table against the Role.
But, it doesn't work alone in a Card Visual.
What changes do I need to make in it to make it work on a card visual.
The SELECTEDVALUE function will return a blank if it sees more than one value. Take out the FILTER function if you want it to work for all selected roles.
Role_Skills = CONCATENATEX ( Jobs, Jobs[Skills], "," )

PowerBI DAX get COUNT DISTINCT with GROUP BY , see SQL query below

I have got this following SQL query that gives me the correct value from the database.
SELECT
SUM( DISTINCT_ORDER_NUMBERS )
FROM
(
SELECT STORE_KEY,
COUNT( DISTINCT TRANSACTION_NUM ) AS DISTINCT_ORDER_NUMBERS,
DATE_KEY,
TRANSACTION_TYPE_KEY
FROM Pos_Data
GROUP BY STORE_KEY,
DATE_KEY,
TRANSACTION_TYPE_KEY
)
AS A
I am however facing challenges writing a DAX formula for a measure in Power BI Here is what I have tried so far but I get an error.
Total Number Of Orders
VAR _TotalOrders =
SUMMARIZE('Pos_Data',
'Pos_Data'[STORE_KEY],
'Pos_Data'[DATE_KEY],
'Pos_Data'[TRANSACTION_TYPE_KEY],
"DISTINCT_ORDER_NUMBERS",
DISTINCTCOUNT('Pos_Data'[TRANSACTION_NUM]))
RETURN SUM(_TotalOrders[DISTINCT_ORDER_NUMBERS])
Please assist
The SUM function expects a base table rather than a calculated table.
Try this instead:
VAR _TotalOrders =
SUMMARIZE('Pos_Data',
'Pos_Data'[STORE_KEY],
'Pos_Data'[DATE_KEY],
'Pos_Data'[TRANSACTION_TYPE_KEY],
"DISTINCT_ORDER_NUMBERS",
DISTINCTCOUNT('Pos_Data'[TRANSACTION_NUM]))
RETURN SUMX(_TotalOrders, [DISTINCT_CHECK_SEQ])
Edit: If the difference you mentioned is related to nulls, then try this in place of DISTINCTCOUNT.
COUNTAX( DISTINCT( 'Pos_Data'[TRANSACTION_NUM] ), 'Pos_Data'[TRANSACTION_NUM] )
The COUNTAX function (as opposed to COUNTX) does not count nulls.

DAX - Stuck on dynamic MAXX column formula

I'm working in Power BI.
I have a table with member card usage data called NonSameDayUses:
https://www.screencast.com/t/yeSjoqonZ
I have another table with member card add data called AddsOnly:
https://www.screencast.com/t/zlPBRWaDqC
The tables are related by the GUID_TranDate2 field. I am trying to add a column to NonSameDayUses that provides the date just before the use date (to calculate when the amount used was added to their card). I have tried a million things, but this is my current formula and I can't figure out what is wrong with it:
DateAdded =
MAXX (
FILTER (
AddsOnly,
AND (
AddsOnly[member_guid] = [member_guid],
AddsOnly[ValueAddDate] < [TransactionDate]
)
),
AddsOnly[TransactionDate]
)
Neither filter is working for me. If I try it with just the first argument (member_guid), I get blanks. If I try with the second (dates) I get the max date for the whole table with no filtering.
Any help would be sooooooooooo appreciated, as I am currently banging my head against the wall! :)
Try qualifying all the column names, it should work:
DateAdded =
MAXX(
FILTER(
AddsOnly
, AND(
AddsOnly[member_guid]
= NonSameDayUses[member_guid]
, AddsOnly[ValueAddDate]
< NonSameDayUses[TransactionDate]
)
)
, AddsOnly[TransactionDate]
)