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 OverflowI 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.
Videos
Try this below measure. Remember, this is not a replacement to the original column or value. But you can use this measure in table or other visual to show "No Vendor" where there is no data in the original column. This way you can keep original and customize both data.
vendor_name =
var current_row_name = MIN(table_name[Name])
RETURN
IF(
current_row_name = BLANK(),
"No Vendor",
current_row_name
)
If you need a calculated column, you can try this below code-
vendor_name_column =
var current_row_name = table_name[Name]
RETURN
IF(
current_row_name = BLANK(),
"No Vendor",
current_row_name
)
You can not resolve your probleme with a measure, its not what measures do. to resolve your probleme consider two approches :
1- the best solution is to replace blank values in power query editor.
2- the second solution is using a calculated column with an if condition.
We can agree (Blank) is super ugly to see on a report cause it just looks broken. but Zero....0000000 looks so good.
I use it as my simple trick that took too long to learn example when talking with over PowerBI developers and inevitably someone in the group facepalms when they realize it was that simple all along.
To do this is at the end of any measure / new column code etc, just add "+0" without quotations to the end of the code line and rejoice should show 0 now.
Measure = COUNT(<column>)
If there is no value in the above they will show (Blank) by default because adding nothing of no type is just that blank.
Measure = COUNT(<column>) +0
This +0 changes things to a math equation which provides a minimum value of 0.
Hope this helps someone and happy Friday.