I currently have a bar graph in power-bi. The graph has distinct id's on the x axis and the amount of mail they received on the y axis. In the Table I am using, I have SalesYear, id, and a Val column which has the value 1 in each row. The id shows up multiple times in the table, sometimes more than twice in the same year.
The problem is I want the graph reversed. I would like to bucket people based on how much mail they received. Then use a slicer to see how much they receive per year. I have been struggling to find a solution on my own, would anyone have any ideas on how to approach this.
Table l looks like this:
id | salesYear | Val
10 | 2012 | 1
11 | 2012 | 1
11 | 2013 | 1
10 | 2012 | 1
10 | 2013 | 1
12 | 2012 | 1
12 | 2012 | 1
So in the visualization I want to show that on the x-axis that people who received 1 piece of mail = 0, 2 pieces of mail = 2, 3 pieces of mail = 1. My question is how can i achieve this will a Stacked Column chart. Any suggestions would be greatly appreciated!
15k | Y axis would be amount of people who recieved 1 piece, 2 piece, etc..
14k | _
13k | | |
12k | _| |
11k || | |
10k ||_|_|_________________________
1 2 3 4 5 6 7 8 9 <-AmountOfMailRecieved
1) Starting with your sample data in Power BI.
2) Create a new calculated table that is a distinct list of years from your source table.
Years = DISTINCT(
SELECTCOLUMNS(
Mail,
"SalesYear", Mail[salesYear]
)
)
3) Create another calculated table that crossjoins the year table with a series of integers. Power BI might indicate the [Value] has an error (like it does for me in the picture below), but it works properly.
MailCounts = SELECTCOLUMNS(
CROSSJOIN(Years, GENERATESERIES(1, 20)),
"SalesYear", Years[SalesYear],
"MailReceived", [Value]
)
4) Add a calculated column that counts the number of IDs in the source table that match the year and mail count. For example, the first row is counting how many distinct IDs show up exactly once in the source table for the year 2012; it's 1 because only ID 11 shows up in 2012 once.
PersonCount = CALCULATE(
DISTINCTCOUNT(Mail[id]),
FILTER(Mail,
Mail[salesYear] = EARLIER(MailCounts[SalesYear]) &&
EARLIER(MailCounts[MailReceived]) = CALCULATE(
COUNTROWS(Mail),
FILTER(Mail,
Mail[salesYear] = EARLIER(Mail[salesYear]) &&
Mail[id] = EARLIER(Mail[id])
)
)
)
)
5) Create relationships between your source table and the year table, and then between the year table and the count table. This will allow the creation of a slicer based on the year of your source table to filter the results from the count table.
6) Optionally, you can hide the year field in the source and count tables. After doing that if you desire, create a chart as configured in the picture below
7) Create a slicer from the year table as shown in the picture below.
And that's it. The chart should match with your expected outcome and can be filtered by year.
You'll be using DISTINCTCOUNT either in a measure or a column.
VariableName = DISTINCTCOUNT([AmountofMailReceived])
Related
I have been working on this Power BI Report and would like some assistance with a slicer used for a matrix.
I need the slicers "MB Data Used", "Calls Made", and "SMS Sent" to slice the Matrix Grand Total fields (on the far right) instead of the value fields. My current slicers work great on the value fields.
Data is filled by a table:
----------------------------------------------------
|ph_id | month | data_used | calls_made | sms_sent |
| 1 | 1/1/19| 123 | 0 | 33 |
| 2 | 1/1/19| 87 | 22 | 0 |
| 3 | 1/1/19| 0 | 0 | 0 |
| 1 | 1/2/19| 0 | 55 | 33 |
| 2 | 1/2/19| 87 | 22 | 77 |
| 3 | 1/2/19| 0 | 0 | 0 |
----------------------------------------------------
Which links to a few others to get related data.
My goal is to be able to see which phone numbers have had no data/call/sms use over the last X months instead of just filtering the ones which contain a 0. In this scenario, when the slicers are all set to 0 and the date range is set 1/1/19-1/2/19, only ph_id 3 should show.
Edit:
W.B. - see this image
You need to use another, unrelated table for your slicers. The best way to create such table is to use the what-if parameter option in the modelling tab (assuming you have any recent version of PBI Desktop).
Or, if you want to base the slicer on number of calls from actual data, you would create the slicer table using New table option and the following formula: CallSlicer = GENERATESERIES(MIN(Data[calls_made]), MAX(Data[calls_made]), 1). The one at the end indicates the step, so you can adjust it, if you want your users to use the slicer in, for instance, increments of 10 or 20.
Now, when you use the generated CallSlicer column, which looks like this:
You will be able to filter your results like this: Your filtered measure = CALCULATE([your_measure], FILTER(Data, Data[calls_made] >= MIN(CallSlicer[CallSlicer]) && Data[calls_made] <= MAX(CallSlicer[CallSlicer]))). You then use your filtered measure in the matrix visual.
EDIT:
Here's a working sample: https://1drv.ms/u/s!AmqvMyRqhrBpgtRGGbJ6w-b66uBENQ?e=67JduS
I've updated the sample - now it shows 2 scenarios. One table reacts to the slicer at individual cell level, the other one at the grand total level.
The key to have the first table working is shown above, below is a solution for the second table, that filters rows at the grand total level:
Create a measure that will show sum for all dates/months, as an example:
CallSumTotal =
VAR tab =
FILTER (
CALCULATETABLE (
SUMMARIZE ( Data, Data[id], "calls_made", SUM ( Data[calls_made] ) ),
ALLSELECTED ( Data[month] )
),
[calls_made] >= MIN ( CallSlicer[Value] )
&& [calls_made] <= MAX ( CallSlicer[Value] )
)
RETURN
SUMX ( tab, [calls_made] )
Now in the matrix use a regular sum measure, but create a visual level filter for CallSumTotal and set it to is not blank
I have a table that contains multiple columns with their named having either the suffix _EXPECTED or _ACTUAL. For example, I'm looking at my sold items from my SoldItems Table and I have the following columns: APPLES_EXPECTED, BANANAS_EXPECTED, KIWIS_EXPECTED, APPLES_ACTUAL, BANANAS_ACTUAL, KIWIS_ACTUAL (The Identifier of the table is the date, so we have results per date). I want to show that data in a table form, something like this (for a selected date in filters:
+------------+----------+--------+
| Sold items | Expected | Actual |
+------------+----------+--------+
| Apples | 10 | 15 |
| Bananas | 8 | 5 |
| Kiwis | 2 | 1 |
+------------+----------+--------+
How can I manage something like this in Power BI ? I tried playing with the matrix/table visualization, however, I can't figure out a way to merge all the expected and actual columns together.
It looks like the easiest option for you would be to mould the data a bit differently using Power query. You can UNPIVOT your data so that all the expected and actual values become rows instead of columns. For example take the following sample:
Date Apples_Expected Apples_Actual
1/1/2019 1 2
Once you unpivot this it will become:
Date Fruit Count
1/1/2019 Apples_Expected 1
1/1/2019 Apples_Actual 2
Once you unpivot, it should be fairly straightforward to get the view you are looking for. The following link should walk you through the steps to unpivot:
https://support.office.com/en-us/article/unpivot-columns-power-query-0f7bad4b-9ea1-49c1-9d95-f588221c7098
Hope this helps.
I'm new to power BI and i require your assistance. I want to create a visualisation showing the average number of tickets from the previous 3 months and compare it with the current month. Is there any easy way to do this?
I have tried many solutions online but it dosen't work. I think it is because my dataset may not suit the solution.
My data:
Tickets | Date
1 | 6/30/2019
1 | 6/10/2019
1 | 7/1/2019
0 | 7/2/2019
1 | 6/30/2019
There are many more columns and rows. The value of ticket is either 1 or 0 and the date can be repeated. This is the data i received from an API.
This is what i currently have
The data would get bigger and bigger as time goes by.
I would want to add a 3month rolling average line in this current visualization that i have.
Thank you!
Here we go:
First I created a column FirstDayMonth,this I use to group all data of the same month
FirstDayMonth = EOMONTH(Tickets[Date];-1)+1
My table looks like:
Next I create a summarized table grouped by the FirstDayMonth
TicketsMonth = SUMMARIZE(Tickets;Tickets[FirstDayMonth];"Amount"; SUM(Tickets[Tickets]))
I add a column Ave3PrevMonth
Ave3PrevMonth =
var totalMonths = YEAR(TicketsMonth[FirstDayMonth]) * 12 + MONTH(TicketsMonth[FirstDayMonth]) - 3
var periodStart = DATE(totalMonths/12;MOD(totalMonths;12);1)
var periodEnd = TicketsMonth[FirstDayMonth]
return
CALCULATE(SUM(TicketsMonth[Amount]);
FILTER(TicketsMonth; TicketsMonth[FirstDayMonth] >= periodStart && TicketsMonth[FirstDayMonth] < periodEnd))/3
This is the tricky bit as Power bi is not strong with dates..
I added an extra column PeriodStart to show the date from where average is taken:
PeriodStart =
var totalMonths = YEAR(TicketsMonth[FirstDayMonth]) * 12 + MONTH(TicketsMonth[FirstDayMonth]) - 3
return DATE(totalMonths/12;MOD(totalMonths;12);1)
End result:
I have a table that is a summary of my actions for my clients and the time I've spent doing it.
So a row would look like this :
Client | Time |Week of the Year | Action
------------------------------------------
Client 1 | 1 | 1 | Summarize action
Client 2 | 2| 1 | Summarize action
And I Would like to add a column (either a calculated column or a measure) that return the sum of time spent on the selected client for the selected week
So each row that contains "client 1" && "Week 1" show the total amount of time spent during "week 1" for "client 1" and I have no idea how to do that in powerbi ...
Simply adding [Client], [Week of the Year] and [Time] to a new table visual should do the trick. Just make sure that you're not summing the values of [Week of the Year], since it seems to be a numeric column from the example you posted:
I have two tables which contain the same data - TableA (PersonId, ItemId, Session) and TableB(PersonId, ItemId, Session). Here is some test data:
PersonId | ItemId | Session
-------------------------------------------------
1 | 1 | Summer 2017
1 | 1 | Spring 2017
2 | 1 | Summer 2017
2 | 2 | Summer 2017
3 | 5 | Spring 2017
There are two slicers for the different sessions (for simplicity I have only showed two in the test data but they may be a lot more). The user has to see the number of different PersonIds for the selected session in the first slicer by
ItemId. Then there should be information on the number of PersonIds that are both present in the first and second sessions in the selected slicers.
My idea is to filter TableA by the selected value in the first slicer and then filter TableB by the selected value in the second slicer, but I am not sure how to do that dynamically? Also, I may need a third table for the intersection of filtered TableA and Filtered TableB. Do you have any ideas on how I achieve this functionality?