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
Related
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" )
)
So, I have two tables I need to combine without merging as I was told merging the tables does not auto update when posted so had to separate my tables. So, I have Fioptics and legacy tables where I pull RecordID, JobTypeID and CustTypeID individually below is how my code looks
legacy res install =
CALCULATE (
COUNT ( LEGACY[RecordID] ),
FILTER (
LEGACY,
LEGACY[JobTypeID] = 1
&& LEGACY[CustTypeID] = 1
&& LEGACY[prod_grouping] = "legacy"
)
)
and
fioptics res install =
CALCULATE (
COUNT ( FIOPTIC[RecordID] ),
FILTER (
FIOPTIC,
FIOPTIC[JobTypeID] = 1
&& FIOPTIC[CustTypeID] = 1
&& FIOPTIC[prod_grouping] = "fioptics"
)
)
how do I go about using a dax function to pull from both RecordID's, JobTypeID and CustTypeID and filter from my FIOPTICS AND LEGACY tables at the same time? It might be a simple answer but having a brain fart maybe overlooking a simple solution to this problem.
You can combine those columns in a calculated table
Combined =
UNION(
SELECTCOLUMNS(
LEGACY,
"RecordID", LEGACY[RecordID],
"JobTypeID", LEGACY[JobTypeID],
"CustTypeID", LEGACY[CustTypeID]
),
SELECTCOLUMNS(
FIOPTICS,
"RecordID", FIOPTICS[RecordID],
"JobTypeID", FIOPTICS[JobTypeID],
"CustTypeID", FIOPTICS[CustTypeID]
)
)
And of cause you can filter the combined table in your report to your needs.
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/
I know this must be extremely simple, but every example I can find online only works within a single table. I've simplified my situation to these two tables:
I want to add a calculated column to the first table, showing the most recent value for that id. It also needs to work with text.
There are a variety of ways to do this kind of thing as I've explained before and all of the solutions there can be adjusted to work in this case.
Doing this as a calculated column and with a second table, you need to make sure you are using row context and filter context appropriately.
Here's are a couple different possibilities I think may work:
MostRecentValue =
MAXX ( TOPN ( 1, RELATEDTABLE ( Table2 ), Table2[date] ), Table2[value] )
In this one, RELATEDTABLE is doing the work of filtering Table2 to only the rows where id matches Table1.
MostRecentValue =
VAR PrevDate = CALCULATE ( MAX ( Table2[date] ) )
RETURN CALCULATE ( MAX ( Table2[value] ), Table2[date] = PrevDate )
The relationship is more subtle here. Wrapping the MAX in CALCULATE forces a context transition so that the row context (which includes id) is applied to Table2 as filter context.
How to construct filter tables for SUMMARIZECOLUMNS function?
The SUMMARIZECOLUMNS has the following pattern:
SUMMARIZECOLUMNS(
ColumnName1, ...
ColumnNameN,
FilterTable1, -- my question concerns this line
FilterTableN,
Name1, [measure1],
NameN, [measure2],
)
I have checked that the following 3 patterns work. They return the same results, at least for the simple sample data I used.
SUMMARIZECOLUMNS (
T[col],
FILTER( T, T[col] = "red" )
)
SUMMARIZECOLUMNS (
T[col],
CALCULATETABLE( T, T[col] = "red" )
)
SUMMARIZECOLUMNS (
T[col],
CALCULATETABLE ( T, KEEPFILTERS ( T[col] = "red" ) )
)
Is any of these patterns superior over the other?
Reference: https://www.sqlbi.com/articles/introducing-summarizecolumns/
Update
I would be interested in an answer that contains a query plan analysis
or link to credible source. I would be grateful if you mentioned
using the SUMMARIZECOLUMNS function when grouping columns from
multiple tables.
You can also construct them the way PowerBI does, using VAR:
VAR __MyFilterTable = FILTER( T, T[col] = "red" )
RETURN
SUMMARIZECOLUMNS (
T[col],
__MyFilterTable
)
Which is more efficient will depend on the complexity your filtering, so there is no "one size fits all" rule necessarily. For a simple table level filter, just FILTER will suffice. I caution you that Line 1, where you're filtering the entire table T, is a bad idea. It's much more performant to only filter a single column. When you filter the entire table, DAX materializes the entire table in memory, while the following just materializes the one value of T[col]:
VAR __MyFilterTable = FILTER( ALL(T[col]), T[col] = "red" ) // This is better.
RETURN
SUMMARIZECOLUMNS (
T[col],
__MyFilterTable
)
You can do even better than that, conceptually. You can basically tell DAX, "I know this is a value, so don't even look in the table for it. Just make me a table and treat it as though I filtered it. Like this:
VAR __MyFilterTable = TREATAS ({"red"}, T[col] )
RETURN
SUMMARIZECOLUMNS (
T[col],
__MyFilterTable
)
Again, this is the pattern that PowerBI uses when performing its filters.
BTW, Creating the filter tables a the top vs. creating them inline with SUMMARIZECOLUMNS() won't make any difference for speed. Avoid using CALCULATETABLE() as you've done here generally.
You can also do this as well, though you aren't likely to see a speed increase generally:
CALCULATETABLE(
SUMMARIZECOLUMNS (
T[col]
),
KEEPFILTERS(T[col] = "red")
)