How to deal with multiple ids multiple categories table to reach THIS on Power BI - powerbi

I have a problem that i was trying to solve 3 days ago and i'm not able to.
I have the following tables:
Companies
company_id
sales
1
2000
2
3000
3
4000
4
1000
Categories
company_id
category
1
medical
1
sports
2
industrial
3
consumption
4
medical
4
consumption
All i want to reach is a COLUMN CHART with a CATEGORY SLICER where i choose the category and i see the TOP 5 companies by category and sales. Yes, in this example the TOP is not needed but in my real case i have 400 companies so i want to:
Select and Show only the required category.
In that category, show only the 5 better companies by sales.
The problem here is Power BI takes all the companies for the TOP N filter so if i choose a category, and also try a top 5, if the companies are not in the TOP5 all companies list, it doesn`t show anything.
Thanks!

If you always want to show the same Top N values in your visual, you can use the filter pane to achieve that.
Below a walk through:
The to add the Top N filtering, I add the following:
It is in Dutch, so a little clarification:
I add a 'filter on this visual'
I selected Populairste N, which is Top N
And as a value I drag and dropped the maximum of sales.
Results:
Things to keep in mind:
You are using a many to many relationship, make sure that this is activated in the Power BI model.
Make sure the direction of filtering is from category to sales, otherwise the slicer will not work. It looks like this:

Related

All rows and total of the rows showing same values in power BI

I am trying to show "Some Column Name" against "Total Amount" in Power BI.
I am expecting the following results:
But instead it's showing me the following results:
The current data type is "fixed decimal number" I tried changing it to "Decimal number" or "Whole Number" but it did not work.
Any suggestions?
The reason why you have a single repeating value is because you did not create a relationship in powerbi model. If for example you have two tables Sales and Staff and you want to sum all staffs sales.
if no relationship created between table in power BI
The output will look like this
However when a relationship is created between the tables
The output will be correct
This is almost certainly the result of a many-to-many relationship in Power BI. In Power BI if there are connections between two (or more) tables that evaluates to a many-to-many relationship then Power BI is unable to make a distinction between any two rows and instead will project the same value for any given row placed in a visual.
Here's an easy way to visualize this:
Table 1 Table 2
Product | ID AmountSold | ID
Widget 1 10 1
Smidget 1 20 2
Gidget 2 5 1
When you join these Power BI can't tell the difference in Sales between Widget and Smidget because they have the same ID. As far as Power BI knows Widget could have sold 0 and Smidget sold a total 15, or Widget sold a total 5 and Smidget sold a total 10, etc.
As a result of this many-to-many relationship Power BI panics and evaluates them to be the same result because it can't determine what is right. Widget and Smidget both sold a total of 15:
Visual
Product | AmountSold
Widget 15
Smidget 15
Gidget 20
You're experiencing the same issue in your data model, although it is undoubtedly a much more complex relationship than the one I just laid out. You need to go back and determine what table(s) are experiencing a many-to-many relationship and fix the issue. Based on the information you've provided it can't be done from here.

DAX Calculate Sum of sales per productid filter by productid ( NOT IN TOP 20 )

I am fairly new to PowerBI DAX and I want to filter out the top 20 product ids in a measure.
I came up with this formula but it does not seem to be working and I was hoping to get some help here.
$ Amount Parcel =
CALCULATE(
SUM(Data[$ Amount Parcel]),
FILTER (Data, NOT (Data[idProduct], SUM(Data[NetSales])) IN TOPN(20, SUMMARIZE(Data, Data[idProduct], "NetSales", SUM(Data[NetSales]))))
)
I want to show sales per PID for all products except for our 20 best sellers.
Thank you !!
I would suggest an easier approach adding a dimension column.
First of all, you need to have Product dimension table separated from Sales fact table. Make sure to create one-to-many relationship between Product and Sales with "Single" cross filter direction.
Then you can create a calculated column on Product table, which can be used to filter out top selling products.
Sales Rank = RANKX('Product', CALCULATE(SUM(Sales[SalesAmount])))
Now drag and drop Sales Rank field into the Filters pane of your visualization, and set the filter condition so that top selling products will not be shown.

How to display subgroup totals in a table visual in Power BI?

I need to display subgroup totals in a table visual in Power BI. However, Power BI is showing me incorrect totals. How do I create a measure to show this?
My current table visual is:
My table relationships are:
What I need is:
SiteName LiftName Amount
Site 1 Lift 1 668.00
Site 1 Lift 2 668.00
Site 2 Lift 3 604.00
Site 3 Lift 4 9.54
Site 4 Lift 6 9622.50
Site 4 Lift 8 9622.50
Site 4 Lift 9 9622.50
I have tried adding an inactive relationship and using that with a USERELATIONSHIP function, but it gives me the same as what I have already:
SiteAmount = calculate(sum(Sales[Amount]),USERELATIONSHIP(Sales[SiteID],Sites[SiteID]))
Is there any way to get this table to display as needed? I cannot amend the relationships in the model to link Sales table with Sites table directly. See below PBIX if needed:
https://1drv.ms/u/s!AuiIgc_S9J5JhbYbCO2jbeQPfpzmXw
Cheers
What you want, it seems to me, is the sum of [Amount] without any filtering except for Site. DAX provides the ALLEXCEPT function to do this kind of filtering.
Unfortunately, the field that whose influence we're trying to ignore is part of the relationship to the tables in the visual. So we get some weirdness and I think it's unavoidable. We can ask DAX to hide those rows as a second step.
SiteAmount =
Var Amount = CALCULATE(
SUM(Sales[Amount])
, ALLEXCEPT(Sales,Sites[SiteName]
))
RETURN IF(ISBLANK(SUM(Sales[Amount])),BLANK(), Amount)

Creating Relationships while avoiding ambiguities

I have a flat table like this,
R# Cat SWN CWN CompBy ReqBy Department
1 A 1 1 Team A Team B Department 1
2 A 1 3 Team A Team B Department 1
3 B 1 3 Team A Team B Department 1
4 B 2 3 Team A Team C Department 1
5 B 2 3 Team D Team C Department 2
6 C 2 2 Team D Team C Department 2
R# indicates the RequestNumber,
Cat# indicates the Category,
SWN indicates the Submitted Week Number,
CWN indicates the Completed Week Number,
CompBy indicates Completed By,
ReqBy Indicates Requested By,
Department Indicates Department Name,
I would like to create a data model that avoids ambiguity and at the same time allows me to report on Category, SWN, CWN (needs to be only a week number), CompBY, ReqBy, Department through a single filter.
For example, the dashboard will have a single filter choice to select a week number.If that week number is selected, it will show the details of these requests from submitted and completed week number. I understand this requires the creation of a calendar table or something like that.
I am looking for a data-model that explains the cardinality and direction(Single or both). If possible, kindly post the PBIX file and repost the link here.
What I have tried: Not able to establish one of the four connections
Update: Providing a bounty for this question because I would like to see how does the Star schema will look like for this flat table.
One of the reason I am looking for a star schema over a flat table is - For example, a restaurant menu is a dimension and the purchased food is a fact. If you combined these into one table, how would you identify which food has never been ordered? For that matter, prior to your first order, how would you identify what food was available on the menu?
The scope of your question is rather unclear, so I'm just addressing this part of the post:
the dashboard will have a single filter choice to select a week number. If that week number is selected, it will show the details of these requests from submitted and completed week number.
One way to get OR logic is to use a disconnected parameter table and write your measures using the parameters selected. For example, consider this schema:
If you put WN on a slicer, then you can write a measure to filter the table based on the number selected.
WN Filter = IF(COUNTROWS(
INTERSECT(
VALUES(WeekDimension[WN]),
UNION(
VALUES(MasterTable[SWN]),
VALUES(MasterTable[CWN])))) > 0, 1, 0)
Then if you use that measure as a visual level filter, you can see all the records that correspond to your WN selection.
If you can clarify your question to more closely approach a mcve, then you'll likely get better responses. I can't quite determine the specific idea you're having trouble with.

Power BI Marketshare with DAX

I got really stumped for my whole day on how to display marketshare on Power BI. My data is kind of complicated but I will try to simplify the problem in here, assume I have two tables:
Dimension Supplier:
FactInvoice:
I would like to display the marketshare (Sum of Spend) for one specific supplier compared to others, with slicer and pie char like this:
So if user choose Supplier 2, the pie chart will show the marketshare of supplier 2 compared to others. I am not sure how DAX can support this
If the Pie chart is not possible, is there any way to show this concept on the Power BI, it does not matter which visual we can use?
Step 1 create data model like below image
Step 2: create two measures
Other Supplier = CALCULATE(SUM(FactInvoice[Spend]),FILTER(FactInvoice,FactInvoice[SupplierID]<>MAX(SupplierDup[ID])))
Selected Supplier = CALCULATE(SUM(FactInvoice[Spend]),FILTER(FactInvoice,FactInvoice[SupplierID]=MAX(SupplierDup[ID])))
Create your report( if you not select any supplier then comparison will be in between max id of supplier to others)
your report
download PowerBI file
First:
calculate % each company spend to total company using formula:
Company/total Spend Percentage = DIVIDE([Company Spend],[AllCompany Spend],0)
Second:
Subtract each company from total % i.e.= 1
Other company Spend% = 1-[Company/total Spend Percentage]
Put both measure in Pie Chart.