Power BI count null rows - powerbi

I have two columns. Both have a general key INT value called TicketId, but one table has less TicketIds than another table. Both tables have different quantity of columns, so =EXCEPT() formula wouldn't fit.
For example, the current counting of rows looks like this:
Dates
Tab1
Tab2
08.11.2022
1058
950
09.11.2022
1058
1056
22.11.2022
2342
302
I am looking for a DAX measure forluma that will calculate TicketIds that exist in Tab1, but doesn't exist in Tab2. It should be not a formula like 1058 - 950 = 108. Because after there will be drillthrough to show all the TicketIds that were calculated (exist in Tab1 and doesn't exist in Tab2).
Dates
Tab1
Tab2
Tabcross
08.11.2022
1058
950
108
09.11.2022
1058
1056
2
22.11.2022
2342
302
2040

Let's say you have a model like this:
and your datasets like this:
Define your measures like this:
OnlyTable1 = COUNTROWS(VALUES(table1[TicketId]))
OnlyTable2 = COUNTROWS(VALUES(table2[TicketId]))
ID_Difference = COUNTROWS(EXCEPT(
VALUES(table1[TicketId]),
VALUES(table2[TicketId])
))
Then if we put it on a table visual:

Here is how to apply EXCEPT() to your problem:
TabDiff =
EXCEPT (
VALUES ( Tab1[TicketId] ),
VALUES ( Tab2[TicketId] )
)
Note that this creates a calculated table.

Related

Distinct count of values based on date in DAX

I have a table like shown below:
ID
Date
Asset
Location
145
7/29/22
A
Market
145
7/30/22
A
Warehouse
145
7/29/22
B
Market
145
7/29/22
C
Truck
150
7/30/22
B
Market
145
7/29/22
D
Market
145
7/30/22
A
Market
What I am trying to accomplish is to get a distinct count of IDs for each date with a location filter as well. So I would want a count of ID based on the slicer selected Date of 7/29/22 AND 7/30/22 for the Market Location. The desired result is 2 for the selected dates from the date slicer which directly corresponds to the date column in the table.
I was trying to use this DAX formula and wasn't getting anywhere....
IDsMarket =
CALCULATE (
DISTINCTCOUNT ( 'Products'[ID] ),
ALL ( 'Products' )
)
I have a measure dropped onto a card. I should have specified that. My apologies. I need 1 measure to show me the combined count for the two days selected.
I tried this with countrows as well but of course the result wasn't distinct... Any help would be greatly appreciated!!
The formula you're looking for is
IDsMarket =
CALCULATE(
DISTINCTCOUNT('Products'[ID]),
'Products'[Location] = "Market"
)
The resulting Table will look like this
But if you put the measure on a Card visual, you'll get
So in DAX the same measure can yield 1000 different values - depending on the filter context.
I created a conditional column in Power Query and combined the ID with the "day" number from the date column which allowed me to then do a distinct count on that combined custom column which produced to correct answer. Sorry for all the confusion. One of those days.

Power BI - Show zero/null value on line chart with dates

I'm using a simple table like this to make a report in Power BI:
Order number
Order date
Turnover
001
30/1/2022
10 €
002
30/1/2022
20 €
003
2/2/2022
15 €
I need to create a line chart showing all the dates, even where I have no data (no orders for that day). This is currently how is shown:
You can notice that the 1/2/22 and 3/2/22 are missing due to no order, but I want them to be visible and the value should be 0. This is also affecting the average line because it's calculated based on the days with data, but I need to put into account also the 0-turnover days.
I tried to use the "Show items with no data" on the date dimension and switch the X axis from Continuous to Catergorical and the other way around. I also tried to create a new metric like this:
Total Turnover = IF(ISBLANK(SUM(Orders[Turnover (EUR)])), 1, SUM(Orders[Turnover (EUR)]))
but it's not working.
If I understand your business requirement correctly, you are going to need to do three things:
Make sure you have a date-dimension table in your model. Build the relationship based on your [Order date] column.
Refactor your [Total Turnover] measure as such:
Total Turnover =
VAR TotalTurnover = SUM( Orders[Turnover] )
RETURN
IF(
ISBLANK( TotalTurnover ),
0,
TotalTurnover
)
Build your line chart using the [Date] column from your date table.

How to multiple two columns in a row with max date in PowerBi?

This is my first PowerBi report. 
I've a table structure like this
TransDate UnitsAsOf Price InvestedAmount Stock
01/02/2020 10 12.4 124 APL
01/03/2020 20 13 260 APL
01/05/2020 21 15 315 APL
01/10/2020 1 111 111 BPL
And this is the table Visualization I'm creating
Stock Total invested (Summarized column) Current Value
APL 699 THIS IS A MEASURE column
BPL 111
I just couldn't figure out how to get max(transDate) for each stock and multiple it with the Price of that row?
Any help please?
You can do it like this
measure =
SUMX(TOPN(1, YourTable, YourTable[TransDate], DESC), YourTable[Price] * YourTable[InvestedAmount])
the TOPN will return you the row with the latest date, and in the SUMX you use the fields from that row.
OPTION-1
You can simply create this following measure-
max_date = MAX(your_table_name[TransDate])
Now add a table visual with column - Stock, InvestedAmount (Default SUM applied) and New Measure max_date. The output will be as below-
OPTION-2
You can also add all 3 column - Stock, InvestedAmount and TransDate directly and select Latest for TransDate as shown below and the output will be same-

Make first few rows unresponsive to slicer Power BI

I have a data which looks like below:
Brands Sales Category Index
Brand1 588 A 1
Brand2 846 A 2
Brand3 827 A 3
Brand4 951 A 4
Brand5 673 B 5
Brand6 637 B 6
Brand7 575 B 7
Brand8 995 B 8
Btand9 737 C 9
Brand10 661 C 10
Brand11 729 C 11
Brand12 789 C 12
Brand13 836 C 13
Problem statement :
I am trying to put Category as a slicer. However I want the rows for Category A to be present in the table view irrespective of the slicer which is selected.
Example: Lets say if Category B is selected in slicer , in this case the table should return all rows until Rank 8.
Below is an example of the desired output when category C is selected:
As you can see, the visual table has both Category A and Category C.
Similarly when both B and C are selected, I should be able to display all the categories (A,B and C).
What tried:
I was thinking if we can use a conditional DAX which return 1 for selected values in slicers and mark rest as 0, I could use that as a visual filter and filter out 0. I tried various combinations of Filter with in Filters and SELECTCOLUMN but it did not work. Even the below measure returns all the rows instead of Selected values|| category="A"
test1 = CALCULATE(MIN('Table'[Index]),FILTER(ALLEXCEPT('Table','Table'[Brands]),'Table'[Category]=SELECTEDVALUE('Table'[Category]) || 'Table'[Category]="A"))
I also tried something like:
test = var cat = min('Table'[Category]) return IF(cat = SELECTEDVALUE('Table'[Category])||cat="A",1,0)
But this gives all as 1 , doesnot give 0 for rows which does not match the condition (note I have blocked the slicer interaction here)
Any help would be highly appreciated.
First, you need to separate your slicer table as keeping the value in the same table you can not achieve the requirement. You can create custom table with this below code-
considering your base table name sales
Lets create the custom table category list
No relation can be there between table sales and category list
category list =
SELECTCOLUMNS(
sales,
"Category",sales[Category]
)
Now, create the slicer using new custom table category list and create this below Measure-
is filter =
if(
MIN(sales[Category]) = "A",
1,
if (
MIN(sales[Category]) IN VALUES('category list'[Category]),
1,
0
)
)
Here below is a sample output when C selected-

How do we Pass the multiple selected values of a Slicer inside DAX?

Let's say I have a table like this - [Orders]
Date Amount Category
12/12/2017 100 A
12/12/2017 200 B
12/12/2017 300 C
1/1/2018 400 A
1/1/2018 500 B
And I have a slicer for Category.
If only one single Value is selected, then a measure like this will work
CALCULATE(SUM(Orders[Amount]),FILTER(ALL(Orders), Orders[Category] = SelectedValue(Category))).
When more than one value is selected, how would you pass that inside the DAX Measure?
Try this:
= CALCULATE(SUM(Orders[Amount])
FILTER(ALL(Orders), Orders[Category] IN VALUES(Category)))
In most situations, you should just be able to write SUM(Orders[Amount]) and Power BI will automatically do the filtering for you based on the slicer.