Problem defining appropriate measure in report - powerbi

The table below indicates a minimal example of my raw data:
Product
Order Day
Customer
Units Ordered
Units Delivered
P
Apr 1
X
4
3
P
Apr 2
X
4
3
P
Apr 1
Y
3
1
P
Apr 1
Z
3
1
Q
Apr 1
Z
3
1
Q
Apr 2
W
3
2
R
Apr 3
X
1
0
R
Apr 4
Y
2
0
R
Apr 5
Z
8
8
R
Apr 6
Z
6
6
Based on this I am able to create the following table as a PBI report where I give a product summary:
Product
# diff. Customers Ordered
Total Ordered
Total Delivered
Service Rate
Product-level Service Test
P
3
14
8
0.57
1
Q
2
6
3
0.5
0
R
3
17
14
0.82
1
This final column in the above summary checks whether more then 50% is being delivered. This report can be filtered on Order Day (time filter) as well as Customers.
Now, in a similar fashion, I would like to create a customer summary report:
Customer
# diff. Products Ordered
# Products Passing Service Test
X
2
1
Y
2
0
Z
3
1
W
1
1
It basically summarizes the product report after filtering for specific customers. My problem is the final column called "Products Passing Service Test". I am not able to define an appropriate measure in order to get the right numbers displayed in this column. I tried some other approaches but then it does not work well with the time filter on Customer Orders.
Anyone that can help? Thank you very much!
JD

Related

Power BI : line grouping

I begin to use Power BI, and I don't know how to group lines.
I have this kind of data :
api user 01/07/21 02/07/21 03/07/21 ...
a 25 null 3 4
b 25 1 null 2
c 25 1 4 5
a 30 4 3 5
b 30 3 2 2
c 30 1 1 3
And I would like to have the sum of the values per user, not by api and user
user 01/07/21 02/07/21 03/07/21 ...
25 2 7 11
30 8 6 10
Do you know how to do it please ?
I created a table with your sample data (make sure your values are treated as numbers):
Then create a Matrix visual, with "user" in Rows and your desired columns in the Values section:

power bi: different calculations for several rows

Would you, please, help me to apply different calculations for 2 rows in power BI:
that is, to transform this table:
client_ids products purchased month
1 0 0 jan
2 1A 1 jan
2 1B 1 jan
3 0 0 jan
4 0 0 jan
5 0 0 feb
into this:
purchased jan feb
1 1
0 3 1
That is, to perform calculations:
-on purchased = 0 - count over month, client
-on purchased = 1 - count distinct over month, client
Thank you.
I used the method:
-create the reference to the main query in the query editor
-drop the column with products
-drop duplicates
But this makes downloading the report slower.
To return the expected output, you can use two steps to obtain the result from the data:
Assuming this is your table with date:
First, calculate the month different compared with today to find recently month (you can try other method depend on your data nature):
Mon Diff = (YEAR(NOW()) - YEAR(Sheet1[date])) + (MONTH(NOW()) - MONTH(Sheet1[date]))
Second, rank the recent month as current:
rank =
var ranking = RANKX(Sheet1,Sheet1[Mon Diff],,,Dense)
return
SWITCH(ranking,1,"prior",2,"current")
Third, generate distinct values from purchase column
Table = DISTINCT(Sheet1[purchased])
Fourth, calculate the frequencies of 0 & 1 in Prior Month, the same for Feb
Jan = CALCULATE(COUNT(Sheet1[rank]),Sheet1[rank]="prior",
Sheet1[purchased]=EARLIER('Table'[purchased]))
Feb = CALCULATE(COUNT(Sheet1[rank]),Sheet1[rank]="current",
Sheet1[purchased]=EARLIER('Table'[purchased]))
The New table for the infor (In Jan, purchase 2 has 2 occurrence instead of 1):

Subtract Value at Aggregate by Quarter

Values are for two groups by quarter.
In DAX, need to summarize all the data but also need to remove -3 from each quarter in 2021 for Group 1, without allowing the value to go below 0.
This only impacts:
Group 1 Only
2021 Only
However, I also need to retain the data details without the adjustment. So I can't do this in Power Query. My data detail is actually in months but I'm only listing one date per quarter for brevity.
Data:
Group
Date
Value
1
01/01/2020
10
1
04/01/2020
8
1
07/01/2020
18
1
10/01/2020
2
1
01/01/2021
12
1
04/01/2021
3
1
07/01/2021
7
1
10/01/2021
2
2
01/01/2020
10
2
04/01/2020
8
2
07/01/2020
18
2
10/01/2020
2
2
01/01/2021
12
2
04/01/2021
3
2
07/01/2021
7
2
10/01/2021
2
Result:
Group
Qtr/Year
Value
1
Q1-2020
10
1
Q2-2020
8
1
Q3-2020
18
1
Q4-2020
2
1
2020
38
1
Q1-2021
9
1
Q2-2021
0
1
Q3-2021
4
1
Q4-2021
0
1
2021
13
2
Q1-2020
10
2
Q2-2020
8
2
Q3-2020
18
2
Q4-2020
2
2
2020
2
2
Q1-2021
12
2
Q2-2021
3
2
Q3-2021
7
2
Q4-2021
2
2
2021
24
You issue can be solved by using Matrix Table, and also to add new column to process value before create the table:
First, add a new column using following formula:
Revised value =
var newValue = IF(YEAR(Sheet1[Date])=2021,Sheet1[Value]-3,Sheet1[Value])
return
IF(newValue <0,0,newValue)
Second, create the matrix table for the desired outcome:

Apply filter before query editor steps

I have the following scenario. My datasource looks like this:
Order Item Type Value
1 1 A 14
1 1 B 10
1 1 C 12
1 2 A 12
2 1 C 19
2 1 D 15
2 2 B 11
Now I apply a few steps in the query editor, inter alia, a Group By (by Order and Item), so that my finished table looks like this:
Order Item Value
1 1 36
1 2 12
2 1 34
2 2 11
I am looking now for a possiblity to filter my datasource table before the steps are getting applied (Filter datasource > query steps getting applied > chart changes).
In my example here I would filter the datasource by Type <> B:
Order Item Type Value
1 1 A 14
1 1 C 12
1 2 A 12
2 1 C 19
2 1 D 15
And the final table (chart datasource) would be looking like this:
Order Item Value
1 1 26
1 2 12
2 1 34
I tried it with parameters. But the problem is I need the filter in power bi online, so that the enduser can apply this filter.
Thanks in advance for any ideas !!
Don't apply the grouping in your query. Leave the source table as it is, create a measure which sums Value, and filter Type.
using order and item in a table visual(don't summarise) and for value using SUM of values, which can later be filtered by type should give the desired result.

Two Way EntityCollection Binding to a Two Dimension Data Matrix

I have a Day Strucuture Table, which has following Columns I want to display:
DoW HoD Value
1 1 1
1 2 2
1 3 2
1 4 2
1 5 2
1 6 2
1 7 2
1 8 2
1 9 2
1 10 2
1 11 4
1 12 4
1 13 4
1 14 4
1 15 4
1 16 4
1 17 4
1 18 4
1 19 4
1 20 4
1 21 1
1 22 1
1 23 1
1 24 1
Dow is The Day of Week (Monday etc.), HoD is the Hour of Day and Value is the actual value.
Now I want to Bind this Day Structure Entity Collection directly to a Control so any Changes can be bound TwoWay
Like this Format:
I think the best way to achieve this is to use a Template and/or a converter, but I just dont know how ;)
I already read this article, but Lack of a TwoWay Binding functionality makes it not useful for me :(
I Hope you can help me
Jonny
Again i solved it on my own ;)
For this problem i created a Grid with a fixed amout of rows and columns. Inside this Grid I put a Itemscontrol bound to my List of data. Inside the DataTemplate I placed a Textbox bound to the current value and bound the Grid Row and Columnproperties to the Day of the Week/Hour of Day.
Pro:
The Textbox is TwoWay Databound to a certain Object or Element.
Very Easy to implement if Row and Colum Property is numeric.
Con:
Limited to a fixed amout of Rows/Columns.
Very much Code to write in XAML (Copy and Paste)
Kinda "dirty" Code. Feels not like the best way to do it.
Im still open for other suggestions.