I'll start by saying that I'm fairly new to Power BI and am finding my way around, but really am struggling with the concept of lists in a column. I'll explain where I have got in a made up but real world example - sorry if it is rather long winded.
So for my example I have orders in a restaurant, as per the following table:
ID Person Order Alcohol
1 Bob Pizza,fries,beer Yes
2 Fred Pizza,salad,dressing,wine Yes
3 Pete Lasagne,fries,cola No
4 Dave Pizza,fries,cola No
5 Bob Sundae No
I would like to be able to show on a report
A data card showing the count of orders
A list of all of the orders showing all the columns as they are above
A bar chart showing the number of times each item was ordered
A doughnut showing orders which included alcohol
I'd also like to be able to filter across those visualisations, i.e. clicking a row in a bar chart or a portion of the doughnut filters the other visualisations. So, I could for example see which orders included alcohol, or how many people ordered fries and alcohol.
This is where I am becoming stuck.
In order to get the count of the each of the items ordered, I have duplicated the Order column, calling it OrderItem, and then split OrderItem on the comma delimiter, creating new rows. Doing this gives 14 rows, but allows me to
Show the data card (counting distinct ID)
Show the list of orders (Table visualisation showing the columns other than OrderItem)
Show a bar chart of all of the items and the number of times they were ordered
Show a doughnut of alcohol (BUT it is showing 14 items because it is counting rows in the table rather than the overall orders)
Do the filtering across visuals
So I'd like to know how I can get the count of alcohol to reflect the distinct orders rather than the total number of rows.
One approach I tried was to create a duplicate table in PowerQuery, and split that duplicate into rows for each Order Item. That works to a fashion in that I can use the original table for the alcohol doughnut and the table with a row for each item for the counts.
The downside with that approach is that if I click the "fries" row in the bar chart, it doesn't then filter the alcohol doughnut to show which orders with fries had alcohol.
Any advice on how to get the correct count in the doughut AND the filtering would be very much appreciated!
Separate order by Comma (Already completed)
Unpivot the data. First select the relevant order columns, then click unpivot columns at top.
Now each order has a value to it, so you can begin to specifically start counting each specific order item. These values will be unique.
As you mentioned, the issue now is alcohol, ID, and person are duplicated. This is where measures are important. So for alcohol, you create a measure.
Measure = CALCULATE(DISTINCTCOUNT('Table'[ID]),FILTER('Table','Table'[Alcohol] = "Yes"))
To get the no values, simply do the same measure with "No"
Related
I'm pretty new to Power BI. I'm unsure how to approach this.
I have one visualization that displays the ten most frequently bought products in a time frame that is set by a slicer. In another visualization, I display how those products have been selling over the past few years (this time frame is not determined by the slicer). I want to display only the ten products that come from the first visualization, not the ten most common over the time frame in the second visualization.
How can I accomplish this? The approach I have in mind (and I'm open to others) is to create a true/false column that changes with the first visualization. "True" would be for products that are frequently bought as determined by the first visualization in the slicer-determined time range, and the second visualization would only look at values with a "true" in that column. How can I create a column (or table, maybe?) that changes depending on a visualization?
Clarification: most of the pages will say Top10 ... Actually, the measure used was a simple Top5 that includes products with the same number of orders than the 5th product. Therefore, to avoid dealing with larger images, 7 products will be seen but it is a Top5 ranking. The idea is you can replace it with your custom TopN measure.
What I understood:
The simplification of your model plus the disconnected help table would be:
I have one visualization that displays the ten most frequently bought
products in a time frame that is set by a slicer.
The Date slicer belongs to the Dates table in the Data model.
The table viz represents the number of rows in the sales table in the
current context (for each product within the Date range).
The table viz is sorted according to the [#Rows] measure in descending
order.
The table viz only presents the TopN products even without the presence
of the [#Rows] measure due to the presence of the [TopOrders]
measure within Filters on this visual. [TopOrders] is 1.
On the second page you create:
A slicer with the Dates[Date] column (the same one used on the
previous page).
A matrix with Products[ProductName] on the rows, HDates[Year] on
the columns, and a measure on values.
From the View tab, you select the Sync Slicers option.
Inside the Sync Slicers pane:
In the Sync column, check the boxes related to the necessary pages.
In the Display column uncheck the box that contains the over
years report.
So far all we have done is pass the time frame context from page 1 to page 2.
Since the TopN context depends on the time frame context, we can now use the [TopOrders] measure as a Filters on this visual in the matrix. Again, [TopOrders] is 1.
Why do the numbers differ between rows and not between columns?
Also, in this example, the Sales table only has information up to 12/31/2020 but the visualization shows an additional year and the Sales[Amount] values for each order is $1 so that [#Orders] and [SalesAmount] are the same for easy comparison.
HDates is not related to the model and for each combination of HDates[Year]-Products[ProductName], the [SalesAmount] measure is using the information coming from the previously hidden slicer and the respective Products[ProductName] because the information coming from HDates[Year] has no effect yet.
In order to complete this exercise, it only remains to modify the [SalesAmount] measure in such a way that it removes the filter on the time frame (Dates[Date]) and it recognizes HDates[Year] as Dates[Year].
SalesAmount :=
CALCULATE(
SUM(Sales[Amount]),
ALL(Dates),
TREATAS(VALUES(HDates[Year]),Dates[Year])
)
And this is the final result.
I hope it works for someone or the idea can be improved.
I got a bar chart and I need to re-order the bars show in it. The bars show at which speed a person was driving and are currently sorted by the one that appears most often.
The data is imported in the structure:
The fields named *_id are used for filtering. What is shown in the bars is the count of the gemeten_snelheid column.
As shown in the bar chart the speeds are not sorted by "speed" but by count. Is it possible to re-order the bars so they are arranged by speed, and how would this be done?
I don't really know how to create a working example of this as the data is imported from a database connection, so if any more information is required feel free to ask.
You could create a new column and order by it, you could do it in sql, for example:
case when column1<30 then 1
when column1<40 then 2
when column1<50 then 3
column1_sort
Or you can do it in PowerBI, you could Add Column -> Conditional Column and write your Ifs. Or you can when in PowerBI desktop right click table, select New column and write something like:
Column_sort = if([Column1]="<30",1,if([Column1]="<40",2,if([Column1]="<50",3,4)))
Then select your not sorted column (Column1) and under Column tools there is Sort by column, and from there select column1_sort
Did you tried this below option? Here I am getting your expected output-
I have a line chart with two lines that show attendance scores for each gender (male and female). I would like to only apply/filter one of the lines while the other is disabled from filtering.
This will allow viewers to compare the overall numbers (both genders) with the filtered numbers (each seperate gender). Is there a way to do this?
You can do this by creating a slicer to select between different measures.
You would have to create two new measures (One filtered for male data and other filtered for female data). Using the slicer you can switch between the two measures and achieve what you are looking for.
The following link details the steps:
https://www.burningsuit.co.uk/blog/2018/03/dax-how-to-use-a-slicer-to-select-different-measures/
Sorry if i am wrong but why are you not summing the both attendance in other column and then use it as you want (else might be i dint got your question correctly)
I'm trying to create a column that has a total of values between 3 columns from 3 tables. How would I go about doing this?
The 2 tables are tables of values that share an id, and they are both linked to a table of account by Id. The goal is to add up 3 columns, and place it into a table grouped by the Id.
I've attempted summing them, trying to use the USERELATIONSHIP function, and creating a relationship between them. It seems to give very inaccurate results, as if it's summing all of the totals together, and passing them to each Id. That, or it won't let me use the column, as if it never existed.
EDIT: General Idea of what I'm trying to do (Lines should be pointing to Account's Id column, but I messed up the lines)
EDIT 2: I also forgot to illustrate or mention. There are more columns with information in each table that can't be summarized for each account preventing me from just merging the table together.
Make sure your data model looks like this (change names as you please, but the structure must be the same):
In dimensional modeling, your table "Account" is a Dimension, and both fee tables are Fact tables. The operation of combining data from multiple fact tables that share the same dimension is called "drill-across", and it's a standard functionality of Power BI.
To combine fees from these tables, you just need to use measures, not columns. This article explains the difference:
Calculated Columns and Measures in DAX
First, create 2 measures for the fees:
Fee1 Amount = SUM(Fee_1[Amount])
Fee2 Amount = SUM(Fee_2[Amount])
Then, create a third measure to combine them:
Total Fee Amount = [Fee1 Amount] + [Fee2 Amount]
Create matrix visual, and place Account_ID from the Account table on the rows. Then drop all these measures into the matrix values area, like this:
Result:
Of course, you don't have to have all these measure in the matrix, I just showed them for your convenience, to validate the results. If you remove them, the last measure still works:
Hello Stackoverflow community,
I am a novice in Power BI DAX syntax writing and am desperate for assistance on a problem at work.
Here's the short of it: I have one table which has the RAW data being pulled from Smartsheet. I have a second table I made for a weighted calculation which I cannot figure out how to write.
In this other table I made, I'll call it WEIGHTEDTABLE, I have a [Brand] column with text I typed in when I made the table (Brand1, Brand2, etc). Then I have two columns which I would like to populate with a formula. These two other columns are for Item1 and Item2.
The reason behind this is I can have a graph with just counts of Item1 and Item2 for each brand, but that is not fair/accurate because some brands have more of an item than another (which is why I want to created a WEIGHTED table).
The graph I want to create would have the Brands on the Axis, and the values would be the COUNT of Item1 and Item2 / the appropriate number that I will enter (let's just say it's 25 for Item1 and 10 for Item2).
So ideally, it would be a COUNTIF or IF - if [Brand] from the RAW table = [Brand] from the table I entered, then there would be a COUNT of Item1 from the RAW table divided ( / ) by a 25 or 10.
That's it! Perhaps there is a much easier way to do this. Anything helps and I really appreciate the time and effort that goes into responses!