As a measure, you could do something like below. I'm assuming that you have a model as follows:
- Fact: (Date, ID, Value)
- DimDate: (Date, ...)
- Rates: (ID, Rate)
- Dim: (ID, ...)
With these tables you'd have relationships as below:
- Dim -1:N-> Fact
- Dim <-1:1-> Rates
- DimDate -1:N-> Fact
With the model above, you could then build a visual of:
- Rows: DimDate[Date]
- Columns: Dim[ID]
- Values: [Value Or Rate Measure]
Value = SUM ( 'Fact'[Value] )
Rate = SUM ( 'Rates'[Rate] )
Value Or Rate Measure =
VAR Value = [Value]
RETURN
IF ( ISBLANK ( Value ), [Rate], Value )
This might not do what you want for totals - you didn't specify. So if you need visual totals you might try the following:
Value or Rate - visual totals =
SUMX (
CROSSJOIN ( VALUES ( 'Dim'[ID] ), VALUES ( 'DimDate'[Date] ) ),
[Value Or Rate Measure]
)
You could also handle this in Power Query M, assuming you have the same tables I've described above. I'm assuming each table has an associated query of the same name.
let
Source = Table.AddColumn(Dim, "Date", each DimDate[Date]),
#"Expanded Date" = Table.ExpandListColumn(Source, "Date"),
#"Merged Queries" = Table.NestedJoin(#"Expanded Date", {"id", "Date"}, Fact, {"ID", "Date"}, "Fact", JoinKind.LeftOuter),
#"Expanded Fact" = Table.ExpandTableColumn(#"Merged Queries", "Fact", {"Value"}, {"Value"}),
#"Merged Queries1" = Table.NestedJoin(#"Expanded Fact", {"id"}, Rates, {"ID"}, "Rates", JoinKind.LeftOuter),
#"Expanded Rates" = Table.ExpandTableColumn(#"Merged Queries1", "Rates", {"Rate"}, {"Rate"}),
#"Added Custom" = Table.AddColumn(#"Expanded Rates", "Value Or Rate", each if [Value] = null then [Rate] else [Value]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Value", "Rate"})
in
#"Removed Columns"
Here, we're doing something similar, but at a table level, instead of as a measure. We crossjoin Dim[ID] and DimDate[Date] to get a dense table of all date and ID combinations. Then we left join the original Fact table and the Rates table. Then we add a column that takes [Value] if it exists, or [Rate] if [Value] is null.
Answer from greggyb on Stack OverflowVideos
Hi all,
I'm trying to get a Network days style function working as part of an incident management report. The start date is always present, but the end date isn't always present, which is causing issues with the results.
What I want is to calculate only when the end date is populated. Otherwise ignore it.
Can anyone help with some simple suggestions? Thanks!
I use a measure to populate a card visual. Im calling out top 3 locations per another measure. and because you cant filter cards with a measure, I need to filter the measure.
=filter(all('table'[location], [rank measure]=1)
This works great for single results. But sometimes locations, because I am using SKIP in my ranking, I have multiples and some none at all.
Example of how my ranking looks:
| Location | Rank |
|---|---|
| A | 1 |
| C | 1 |
| F | 3 |
| D | 4 |
So I have two 1st place and no second place. Thats the way I want the ranking to show. So my cards show an error for Rank 1 and BLANK for Rank 2.
I can do an IFERROR, which solves for errors, but not blanks. I can use ISBLANK() but then I will still get the error.
Is there any way to do this? I want the measure to return "Tie, See Table" if there is an error or the result is BLANK. I have tried nesting them both ways, but the error always wins out.