My data is
I'd like to block measure (sum of amount) with one filter Choose = "Home"
When I change slicer on "Not Home" my data change.
I don't want it. When I click "Not home" I want to have same values like I click "Home"
I can't use Edit interactions because I want to add new columns that they will be depended to slicer. I'd like to apply it to only one maesure.
I tried calculate(sum(amount), filter(choose = "Home").
It doesn't work.
Data still change.
What should I do?
Wouldn't this work?
Sum of Amount =
CALCULATE (
SUM ( 'Table'[Amount] ),
'Table'[Choose] = "Home"
)
I think in your original measure you forgot ALL ( 'Table'[Choose] ). The above measure is semantically identical to:
Sum of Amount =
CALCULATE (
SUM ( 'Table'[Amount] ),
FILTER (
ALL ( 'Table'[Choose] ) ,
'Table'[Choose] = "Home"
)
)
I don't have a Windows box to test this simple model, but perhaps you also need to invoke KEEPFILTERS:
Sum of Amount =
CALCULATE (
SUM ( 'Table'[Amount] ),
KEEPFILTERS ( 'Table'[Choose] = "Home" )
)
Related
I'm trying to replicate the example presented in this youtube tutorial
https://www.youtube.com/watch?v=z9ttZAZkEhs
However, even if I use the same DAX code the controls do not recognize the values properly.
Selected = calculate (DimProduct[uniqueCustomer], treatas( Values(Products[Name]), DimProduct[EnglishProductName] ) )
I tried different ways to recognize the values coming from the slicer, but they simply do not work.
CheckColumn = if (trim(DimProduct[EnglishProductName]) = trim(DimProduct[SelectedNumber2]),true,false)
I have attached the example file that I'm using.
https://github.com/gabrielacosta/TestPowerBiSlicer/blob/main/testslicer.pbix
Does anyone know what could be the issue.
I guess your calculation should look like the formula below but it doesn't make much sense doing that calculation.
Selected =
CALCULATE (
[uniqueCustomer],
TREATAS ( VALUES ( Products[Name] ), DimProduct[EnglishProductName] ),
VALUES ( DimProduct[EnglishProductName] )
)
For this specific scenario just using SELECTEDVALUE is better
Selected2 =
VAR SelectedProduct =
SELECTEDVALUE ( Products[Name] )
VAR CountCalc =
CALCULATE (
[uniqueCustomer],
FILTER ( DimProduct, [EnglishProductName] = SelectedProduct )
)
RETURN
CountCalc
So I have a table with employees. Each employee has a manager, and using the PATH function, I can create another column, that traces the management of each employee to the CEO (using employee ID and manager's ID.) For example, if my boss reports to the ceo, my employee path would be "CEO ID | My boss ID | My ID" or "10001234|10002345|1000456."
Once I have this path selected, I need to be able to filter my data based on a list of people (business leaders.) If I select business leader A, then I want my data to only include people who have business leader A in their employee path, i.e., people who eventually report to him. I have a separate table of business leaders. Here's what Im doing:
Create a path for each employee: empPath = PATH(EmployeeTable[Employee ID], EmployeeTable[Manager ID])
Use business leader table as a slicer (using their IDs)
Create a variable, selectedLeader, that records the value of whatever selection has been made from the slicer: selectedLeader = IF(HASONEVALUE('LeaderTable'[Id]),VALUES('LeaderTable'[Id]),BLANK())
Put it all together using PATHCONTAINS to filter assign a binary indicator that will allow us to filter the data:
Filter =
var selectedLeader = IF(HASONEVALUE('LeaderTable'[Id]),VALUES('LeaderTable'[Id]),BLANK())
var empPath = PATH(EmployeeTable[Employee ID], EmployeeTable[Manager ID])
return IF(PATHCONTAINS(empPath, selectedLeader ),1,0)
This however, gives the error: Calculation error in measure: A table of multiple values was supplied where a single value was expected.
I've been trying to play around with the formula a lot, using VALUES, FIRSTNONBLANK and other aggregating functions on employeePath, but none are working as desired. Any help appreciated!
The issue is that you need row context for your PATH function to work as you're expecting. As you have it written, it doesn't know which row of the EmployeeTable you're referring to with empPath.
Try this instead:
Filter =
VAR selectedLeader = SELECTEDVALUE ( 'LeaderTable'[Id] )
VAR FilteredTable =
FILTER (
EmployeeTable,
PATHCONTAINS (
PATH ( EmployeeTable[Employee ID], EmployeeTable[Manager ID] ),
selectedLeader
)
)
RETURN
IF ( ISEMPTY ( FilteredTable ), 0, 1 )
You can make this more efficient if you define a calculated path column on the EmployeeTable first.
Path = PATH ( EmployeeTable[Employee ID], EmployeeTable[Manager ID] )
Then the measure simplifies to:
Filter =
VAR selectedLeader = SELECTEDVALUE ( 'LeaderTable'[Id] )
VAR FilteredTable =
FILTER ( EmployeeTable, PATHCONTAINS ( EmployeeTable[Path], selectedLeader ) )
RETURN
IF ( ISEMPTY ( FilteredTable ), 0, 1 )
I tried to create a measure which should calculate the average number of the selected regions (via Chiclet Slicer).
If there is no filter set it should take the value of the whole country (CH - which is also part of this table).
In terms of logic, it should read something like this: If FilterIsActive take the average of median_R_mean of the selected regions else select the median_R_mean of "CH".
I have tried this :
RE =
IF(
ISFILTERED(Region[Bezeichnung]),
AVERAGE(COVID19Re_geoRegion_Last_value[median_R_mean]),
FILTER(
COVID19Re_geoRegion_Last_value,
"CH"
)
)
Unfortunately this approach does not work.
Can anyone help me on what possible approach I can follow here?
If I understand your issue correct, you are looking for a measure as below-
RE =
IF(
ISFILTERED(Region[Bezeichnung]),
AVERAGE(COVID19Re_geoRegion_Last_value[median_R_mean]),
AVERAGEX(
FILTER(
ALL(COVID19Re_geoRegion_Last_value),
COVID19Re_geoRegion_Last_value[geoRegion] = "CH"
),
COVID19Re_geoRegion_Last_value[median_R_mean]
)
)
I have a survey that is sent to companies periodically and each new survey is given a collection #. I'm trying to create a column that tells me the maximum collection # for each company code. This will vary by company because not every company responds to every survey.
LastCollection = (FILTER('Dynamic', 'Dynamic'[Collection]
=CALCULATE(max('Dynamic'[Collection]),ALLEXCEPT('Dynamic','Dynamic'[Company Name])))
The error I'm getting is that the expression refers to multiple columns. I attempted to wrap it in AVERAGE but that didn't help.
You should just be able to do something along the lines of the below.
LastCollection =
VAR companyName = 'Dynamic'[Company Name]
RETURN CALCULATE( MAX ('Dynamic'[Collection] ),
FILTER ( 'Dynamic', 'Dynamic'[Company Name] = companyName ))
I'm not sure why you have the CALCULATE inside a FILTER since a FILTER returns a table rather than a single value.
This should be simpler:
LastCollection =
CALCULATE (
MAX ( 'Dynamic'[Collection] ),
ALLEXCEPT ( 'Dynamic', 'Dynamic'[Company Name] )
)
I have a table called MachineEvents containing data similar to the one seen above.
I'm trying to create a measured column in DAX containing the current firmware of the machine.
This will be used to filter only messages when the machines has had certain firmware.
I've tried searching around but i have trouble finding similar problems.
Assuming you want your Firmware column to return the latest value from field message_info where message_type = 1, based on event_time, then use this DAX code in your Calculated Column:
Firmware =
VAR LastFirmwareTime =
CALCULATE (
MAX ( MachineEvents[event_time] ),
FILTER (
ALLEXCEPT ( MachineEvents, MachineEvents[machine_id] ),
MachineEvents[message_type] = 1 && MachineEvents[event_time] <= EARLIER ( MachineEvents[event_time] )
)
)
RETURN
CALCULATE (
VALUES ( MachineEvents[message_info] ),
FILTER (
ALLEXCEPT ( MachineEvents, MachineEvents[machine_id] ),
MachineEvents[message_type] = 1 && MachineEvents[event_time] = LastFirmwareTime
)
)
See worked example PBIX file here: https://pwrbi.com/so_60372050/