I have a dashboard in Power BI that tells me all about orders and products.
Imagine you're a clothing store owner where customers can buy in a physical store, by phone and online. Store and phone orders are known as "offline channel". All products can be ordered in an "offline channel" but only specific products can be ordered online. I want to set up a visual in Power BI that helps me see:
what the top x combinations of products are that customers buy in a single order - lets say top 10
how many times each combination of products has been ordered
which of those products in the combination are available in offline channels only
which of those products in the combination are available online
e.g. i'd want an output probably like this table in a matrix visual or something:
Products Ordered Combination
Volume
Available in offline channels only
Available online
AB1, TY2
5000
AB1, TY2
AB1
4500
AB1
AZ9
3500
AZ9
AB1, AZ9
700
AZ9
AB1
AB1, TY2, AZ9
50
AZ9
AB1, TY2
I just don't know how to get my raw data in Power BI into a position where it can be put into a visual. Here are the key tables and fields of data:
ORDERS Table - 1 record per order placed
ORDER_ID ORDER_CHANNEL
-------------------------------
123456 STORE
123457 STORE
123458 ONLINE
987654 PHONE
ORDERS_PRODUCTS Table - shows every product ordered as part of an order
ORDER_ID PRODUCT_ID
-------------------------------
123456 AB1
123456 ZX9
123456 TY2
123457 AB1
123458 AB1
987654 AZ9
987654 TY2
PRODUCTS Table - 1 record per product that is available for customers to order
PRODUCT_ID AVAILABLE_TO_ORDER_ONLINE
-------------------------------
AB1 Y
AZ9 N
TY2 Y
Related
I have two separate tables that are used to calculate total savings of repaired products.
Table_A is a result of my SQL Server query and contains information about all repairs performed on specific products:
Timestamp
Product_serialnumber
Product_name
Repair_reference
Repair_description
2022-10-02 11:52:36.330
Serial_A
Product_A
J1
Damaged
2022-10-02 11:52:37.343
Serial_A
Product_A
J3
Damaged
2022-10-02 11:52:37.720
Serial_A
Product_A
P5
Bent
2022-10-20 03:02:11.713
Serial_B
Product_A
J8
Dirty
2022-10-20 03:03:45.570
Serial_C
Product_B
P40
Damaged
2022-10-20 23:49:54.837
Serial_D
Product_C
P8
Dirty
2022-11-12 08:26:11.270
Serial_E
Product_A
J50
Bent
One Product_serialnumber can be repaired many times.
Table_B is very simple and created manually - it contains information how much each unit of specific product is worth.
Product_name
Value
Product_A
250
Product_B
250
Product_C
175
Both tables are joined with many to one cardinality with single cross filter direction running from Table_B to Table_A.
My task was to create visual to show how many Product_serialnumber s were repaired and how much we saved by repairing them. It is very important to perform DISTINCTCOUNT of Product_serialnumber , not COUNT of all repairs performed on them as 3 repairs on 1 Product_serialnumber worth 250 is still 250 saved, not 750.
In PowerBI I have one table with summary. To calculate savings I created following DAX measure in Table_A:
Measure = DISTINCTCOUNT('Table_A'[Product_serialnumber]) * MAX(Table_B[Value])
It gave me results below:
Product_name
Distinct count of Product_serialnumber
Value
Savings
Product_A
3
250
750
Product_B
10
250
2500
Product_C
25
175
4375
Total
38
9500
Each row has correct Savings value but Total is wrong. Instead of 9500, there should be 7625.
I figured out that MAX(Table_B[Value]) in my DAX Measure simulates 38*250. When I changed that to MIN, it was 38*175. So still wrong
To correct that, what I eventually did was I created New Column in Table_A:
RELATED_Value_from_table_b = RELATED(Table_B[Value])
Now each row in Table_A has correct Value based on Product_name.
Only then I created this measure in Table_A:
Saved = SUMX(
DISTINCT('Table_A'[Product_serialnumber]),
CALCULATE(MAX('Table_A'[RELATED_Value_from_table_b])))
So I got following result:
Product_name
Distinct count of Product_serialnumber
Value
Savings
Product_A
3
250
750
Product_B
10
250
2500
Product_C
25
175
4375
Total
38
7625
Total is finally correct.
Of course I found the solution to the task but I am not happy of how I did it and I believe there is more optimized way of doing it. I want to know it to be better in the future.
I have the following big table over 13 million rows.
ProductCode
ProductName
valueUSD
ExportOrImport
Dest
100100
Fish
120K
Export
China
100100
Fish
122M
Export
Russia
100150
Oil
120B
Export
China
100150
Oil
122M
Export
US
I need to display the following summary table on dashboard.
ProductCode
ProductName
valueUSD
% From total
TopDest
100150
Oil
120.122B
90%
China, US
100100
Fish
122.12M
10%
China, Russia
...
...
...
...
...
I have created a "button" that separates export from import. But now I do not know how to compose TopDest column where I need to show top 5 Countries where particular product ExportedOrImported. Also, how to properly formulate this question for google search? is it grouping by category display topN ?
Any ideas how to create this table??
I have two tables in Power BI as follows:
COUNTRIES
COD COUNTRY
1 BRAZIL
2 ARGENTINA
3 CHILE
4 BRASIL
5 COLOMBIA
6 ARGENTINA
7 URUGUAI
SALES
COD DATE
1 2021-01-02
2 2021-10-01
3 2019-09-04
1 2018-07-05
7 2019-04-10
There's a relationship between the two tables, on the COD column.
I need to count how many countries (column "COUNTRY" from the table "COUNTRIES") have a status CHURN. It's considered CHURN when their latest order from the table "SALES" is more than 180 days, using today as a reference.
I know that I need to group by the MAX date per country, do a DATEDIFF, and then do a COUNT. I've tried using ALL and SUMMARIZE, but I haven't found a way to solve this problem.
Are you able to add a calculated column to store the max sales date for each country in your COUNTRIES table? Either in Power BI or directly in your database. If so, here's one solution with 2 steps.
Create a MaxSalesDate column in your COUNTRIES table. DAX for a calculated column below:
MaxSalesDate =
VAR COD = COUNTRIES[COD]
RETURN MAXX(FILTER(SALES, SALES[COD] = COD), SALES[DATE])
Create a measure that counts the number of MaxSalesDate values that are older than 180 days old:
CountCHURN = COUNTX(COUNTRIES, IF(DATEDIFF(COUNTRIES[MaxSalesDate], TODAY(), Day) > 180, 1))
As per the below scenario,I need to exclude all the rows in the table Sales with columns Client,sales,salesdate and region which fall outside the selected maximum and minimum date range of the date slider.
Could anyone please suggest a DAX , I will share my DAX query which is not working.I tried to search official guides in PowerBI for selectedValues() to handle this date filter condition but nothing seems to be working.
I created a Calendar table with distinct values of the dates as present in the Sales Dates column of the Sales table. There is no relationship between these two tables. I used the below DAX measures to handle the filtering criteria for excluding the rows:-
Below measures are meant to find maximum and minimum dates in the selection slider
MaxDate=MAX(DateDimention[Dates])
MinDate=MIN(DateDimention[Dates])
Below ExcludedMeasure is meant to set 1 flag to the values other than selected values which are selected for both min and max dates.
I dragged and dropped it in the visual filter of my table Sales and set it to dont show.But it seems to be not working.
Please suggest how can I fix it.
ExcludeMeasure = IF (SELECTEDVALUE(Calendar,Calendar[MinDate],0,1),
IF (SELECTEDVALUE(Calendar,Calendar[MaxDate],0,1)
My Present Visualization and independent Calendar table to be used in the filter slider:-
Present visualization
Independent Calendar Table
Input data source [Excel]
Client Sales SalesDates Region
A 1000 1.1.2000 USA
A 100 1.2.2000 USA
A 200 4.3.2000 USA
B 110 4.3.2000 Europe
B 1000 5.4.2000 Europe
B 200 6.8.2001 Europe
C 1100 7.9.2001 Asia
C 2000 8.12.2001 Asia
D 100 1.2.2002 Australia
D 1300 6.3.2002 Australia
E 100 7.5.2002 Africa
Expected Results :
If I select Minimum slider date as 01.04.2001 and maximum slider date as 1.09.2001 in my[Dates] filter visualization, then it should return the below results after excluding '5.4.2001' and '6.8.2001':-
Client Sales SalesDates Region
A 1000 1.1.2000 USA
A 100 1.2.2000 USA
A 200 4.3.2000 USA
B 110 4.3.2000 Europe
C 1100 7.9.2001 Asia
C 2000 8.12.2001 Asia
D 100 1.2.2002 Australia
D 1300 6.3.2002 Australia
E 100 7.5.2002 Africa
Kind regards
Sameer
A relationship between the date table and the sales table would be ideal, as when you filter the date from the date table, the filter would exclude the records from the sale tables.
If you can't have a date table with the relationship, your exclude measure needs to be something like this:
Exclude =
CALCULATE(COUNT(Sales[Id]),
Sales[SalesDates] >= [MinDate] &&
Sales[SalesDate] <= [MaxDate]) > 0
I have an SSAS cube with a FactTicket, that has a TicketsSold measure.
The cube has a good number of dimensions. Lets call them Date, Agent and Geo.
I can create a table (we're using Power BI service, if it makes a difference) and put in it all and any dimensions, and the TicketsSold measure.
What I'd like to do, is have another measure that'll calculate the percent of each row in the table out of the total of the table at that moment.
so suppose I have the following data:
Date Agent Geo TicketsSold
2020-04-01 Moulder US 12
2020-04-01 Moulder UK 4
2020-04-02 Moulder US 10
2020-04-03 Moulder UK 5
2020-04-01 Skully US 16
2020-04-01 Skully UK 12
I would like to be able to filter my report on any measure, display any other measure(s) with the TicketsSold and the percent.
Such as, filtered on 2020-04-01 and 2020-04-02:
Agent Geo TicketsSold %ofTicketsSold
Moulder US 22 40.74 %
Moulder UK 4 7.40 %
Skully US 16 29.63 %
Skully UK 12 22.22 %
TOTAL 54 100 %
Or filtered only on Agent Moulder:
Date TicketsSold %ofTicketsSold
2020-04-01 16 51.61 %
2020-04-02 10 32.26 %
2020-04-03 5 16.13 %
TOTAL 31 100 %
It's clear to me that what I probably need is some way of getting -- for each row in the table -- the total of the table itself, and then dividing the row's own TicketsSold by this total.
But I can't seem to figure out a trivial way of creating such a calculation. Is this doable, without having to define a tuple of all possible dimensions?
Thanks!
You can achive that using the axis function . Below is an example based on Adventureworks
where we will create a PercentageOFTotal Column based on InternetSales
select
{[Measures].[Internet Sales Amount]}
on columns,
non empty {([Product].[Category].[Category],[Product].[Subcategory].[Subcategory])}
on rows
from
[Adventure Works]
where [Date].[Calendar Year].&[2013]
Result
Now lets add our new column
with member measures.PercentageOFTotal
as round(([Measures].[Internet Sales Amount]/sum(Axis(1),[Measures].[Internet Sales Amount]))*100,2)
select
{[Measures].[Internet Sales Amount],measures.PercentageOFTotal }
on columns,
non empty {([Product].[Category].[Category],[Product].[Subcategory].[Subcategory])}
on rows
from
[Adventure Works]
where [Date].[Calendar Year].&[2013]
Result
If you are already using PBI: why don't you make use of DAX? A DAX query is able to solve your problem: MEASURE Fact[Percent] = CALCULATE(SUM(Fact[Amount]), ALLSELECTED(Fact)). "ALLSELECTED" is similar to VISUALTOTALS() in MDX, but more dynamic.