DAX (calculated column, related tables) - dax

I have a table [Delays] with a column called [Delay]. I also have a table [Ranges] with three columns: [Range], [From] and [To]. I need to create a column in the [Delays] table to display the Range value from the [Ranges] table according to this criteria: 'Delays'[Delay] >= 'Ranges'[From] && 'Delays'[Delay] < 'Ranges'[To].
Help is greatly appreciated.

Try creating a measure using:
=CALCULATE(
VALUES(Ranges[Range]),
FILTER(Ranges,
Delays[Delay] >= Ranges[From]
&& Delays[Delay] < Ranges[To]
)
Depending on your table, you may need to use the HASONEVALUE function because if delay falls in multiple ranges, the measure will fail.
This is assuming that the Ranges table and Delays table are not joined together. If they are, you can just add the Ranges[Range] from the Delays table.
SUMMARIZE(
Delays,
Delays[Delay],
Range[Ranges]
)

Related

In DAX, is it possible to check if value exists in another table using measure instead of calculated column?

I'm hoping to create a measure of distinct count of a customer column, on the condition if customers in this column does not exist in another table's customer column.
I know I can create a calculated column checking if the customer exists, and then use the calculate function filtering out those who do exist. But is it possible to achieve this without creating the calculated column?
Please note this is in Power Pivot, not Power BI so I can't really use 'treatas' or 'in'. Thanks a lot.
Assuming tables named Table1 and Table2:
MyMeasure :=
VAR T2Customer =
VALUES( Table2[Customer] )
RETURN
CALCULATE(
DISTINCTCOUNT( Table1[Customer] ),
NOT (
CONTAINSROW(
T2Customer,
Table1[Customer]
)
)
)
Yes, You can achieve it using EXCEPT()function:
Let's say that we have 2 tables like this:
Customer_Table1:
Customer_Table2:
Now we can use this measure to achieve our result:
CountOfDistinctCusts =
COUNTROWS (
EXCEPT (
VALUES ( Customer_Table1[Customer] ),
VALUES ( Customer_Table2[Customer] )
)
)
If we test the code:

Power Query - Modify tables before combining them

On my table (point1) I am trying to get, that for each table of the grouped rows (point 2) I will have new row inserted (point 3) at the beginning of each table with the value in the column "Metadata1" equal to value form "Column2" for original row number 2 (starting counting from 0).
Link to excel file:
https://filebin.net/cnb4pia0vvkg937g
Its hard to know how much of your requirement is generic or specific, but
TransformFirst = Table.TransformColumns(#"PriorStepName",{{"Count", each
#table(
{"Column1","Column2","Metadata1"},
{{_{0}[Column1],_{0}[Column2],_{2}[Column2]}}
) & _
}}),
Together=Table.Combine(TransformFirst[Count])
in Together
modifies all the tables in column Count to include an extra row that is made up up Row0/Col1 Row0/Col2 and Row2/Col2
It then combines all those tables into one table

Tips to sum values and ignore all filter but the fields of two table in Dax?

I have 3 dimensions tables and one fact Table Sales
DimCalendar (Fields Year/Month/Day/Week)
DimCountry (Field : CountryName)
DimManager (Field ManagerName)
FctSales (Field : Amount)
I want to create a measure to Sum the Amount of the Sales (FctSales) and filter only to the fields of the tables DimCalendar and DimCountry.
After research, i was thinking about the function AllExcept, like :
CALCULATE(SUM(Sales[Amt]);ALLExcept(Sales;Country[Country];Calendar[Year]...)
but if i do that, i will have to write every columns of the table Calendar and Table Country in the AllExcept, i am wondering if there is another solution.
Maybe using REMOVEFILTERS() to remove every filter and then put back the filters over DimCountry and DimCalendar might work?
CALCULATE (
SUM ( Sales[Amt] );
REMOVEFILTERS ();
VALUES( DimCountry[CountryName] );
VALUES( DimCalendar[Date] )
)
DimCalendar[Date] should be the column used for the relationship with Sales.
This measure first evaluates the filter arguments in the current filter context.
Using as filter the columns used for the relationships guarantees that whatever the column used for filtering this would be mapped over the relationship.
Then, the REMOVEFILTERS() will remove any existing context filter and eventually the filter arguments evaluated during the first step will be applied, putting back any filtering that was set over DimCalendar and DimCountry.

Sum of only Distinct values in a Column in DAX

I have table[Table 1] having three columns
OrganizationName, FieldName, Acres having data as follows
organizationname fieldname Acres
ABC |F1 |0.96
ABC |F1 |0.96
ABC |F1 |0.64
I want to calculate the sum of Distinct values of Acres
(eg: 0.96+0.64) in DAX.
One of the problems with doing what you want is that many measures rely on filters and not actual table expressions. So, getting a distinct list of values and then filtering the table by those values, just gives you the whole table back.
The iterator functions are handy and operate on table expressions, so try SUMX
TotalDistinctAcreage = SUMX(DISTINCT(Table1[Acres]),[Acres])
This will generate a table that is one column containing only the distinct values for Acres, and then add them up. Note that this is only looking at the Acres column, so if different fields and organizations had the same acreage -- then that acreage would still only be counted once in this sum.
If instead you want to add up the acreage simply on distinct rows, then just make a small change:
TotalAcreageOnDistinctRows = SUMX(DISTINCT(Table1),[Acres])
Hope it helps.
Ok, you added these requirements:
Thank You. :) However, I want to add Distinct values of Acres for a
Particular Fieldname. Is this possible? – Pooja 3 hours ago
The easiest way really is just to go ahead and slice or filter the original measure that I gave you. But if you have to apply the filter context in DAX, you can do it like this:
Measure =
SUMX(
FILTER(
SUMMARIZE( Table1, [FieldName], [Value] )
, [FieldName] = "<put the name of your specific field here"
)
, [Value]
)

how to I define measurement filter from other table in tabular

I am trying to make measure that gets sum of amt column where versiontype column = ative how do I write dax formula for that measure?
So let's say your fact table is called Sales. It has a Sales Amount called Amt. The table is linked to a Version table with a VersionType field that includes a value of "Active".
You could create a new measure for Active Sales as follows:
ActiveSales :=
CALCULATE (
SUM ( Sales[Amt] ),
'Version'[VersionType] = "Active"
)

Resources