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.
Related
My data
Fact
iddimUser iddimtime
123 81200
124 84500
DimTime
iddimtime FullTime
81200 08:12:00.0000000
84500 08:45:00.0000000
Desired Table calculation
iddimUser iddimtime Time
123 81200 08:12:00.0000000
124 84500 08:45:00.0000000
I require to bring to the fact table a specific time from the time dimension base on one of the multiple relationships I have (I have several IdTimes in the fact table).
I tried this column calculation but getting an "A table of multiple values was supplied where a single value was expected" error
FullTime = TIME(
HOUR(CALCULATE( VALUES(DimTime[FullTime] ),
USERELATIONSHIP ( Fact[iddimtime], DimTime[iddimtime]))),
MINUTE(CALCULATE( VALUES(DimTime[FullTime] ),
USERELATIONSHIP ( Fact[iddimtime], DimTime[iddimtime]))),
SECOND(CALCULATE( VALUES(DimTime[FullTime] ),
USERELATIONSHIP ( Fact[IniciaProce], DimTime[iddimtime]))))
FullTime1 =
FORMAT(RELATED(DimTime[FullTime]),"hh:nn:ss")
This you can use as alternative to your measure and it will be much faster.
FullTime2 =
FORMAT(
LOOKUPVALUE(
DimTime[FullTime]
,DimTime[iddimtime]
,[iddimtime]
)
,"hh:nn:ss"
)
Why do you use the userelationship if there is only one active relationship between fact and dim tables ? All you need is the related function to access the related row in the dim table:
Note:
Ensure that The [iddimtime] column is the one who creates the relationship between both tables.
Related() is an iterator. Never use it with a calculate involving USERELATIONSHIP() in a calculated field.
RELATED() is used to access the column values from many side to one-side. Conversely, RELATEDTABLE() is used to access columns from one side to many side.
Please test this, and let me know if It solves your problem.
FullTime =
TIME ( HOUR ( RELATED ( DimTime[FullTime] ) ), MINUTE ( RELATED ( DimTime[FullTime] ) ), SECOND ( RELATED ( DimTime[FullTime] ) ) )
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
I calculated a field that brings the total sales for bikes in 2018-all work fine
copy the same formula to another column to calculate the same for 2017 brought this reference error -how can I move around it if I want to show a few columns using the same formula with different parameters
Sales_Bike_2018 =
CALCULATE (
[Total_Sales],
TrainingSample2[Business Segment] = "Bikes",
TrainingSample2[Year] = 2018
)
Sales_Bike_2017 =
CALCULATE (
[Total_Sales],
TrainingSample2[Business Segment] = "Bikes",
TrainingSample2[Year] = 2017
)
The problem is that you are creating 2 columns on a table that doesn't have a Unique Key.
When you create Sales_Bike_2018 everything works fine because it depends on the rest of the columns of your table but when you create the column Sales_Bike_2017, the code of Sales_Bike_2017 depends on rest of the columns as well as on Sales_Bike_2018.
Similary if it was possible to create Sales_Bike_2017 then Sales_Bike_2018 would have depended upon Sales_Bike_2017 and that's not allowed and that's why you get a circular dependency error.
Solution:
Remove filters coming from both new columns due to context transition by using REMOVEFILTERS ()
Sales_Bike_2018 =
CALCULATE (
[Total_Sales],
TrainingSample2[Business Segment] = "Bikes",
TrainingSample2[Year] = 2018,
REMOVEFILTERS ( TrainingSample2[Sales_Bike_2017] )
)
Sales_Bike_2017 =
CALCULATE (
[Total_Sales],
TrainingSample2[Business Segment] = "Bikes",
TrainingSample2[Year] = 2017,
REMOVEFILTERS ( TrainingSample2[Sales_Bike_2018] )
)
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.