PowerBi Dax code to replicate excel sumif - powerbi

I am looking to calculate
'supplier = (sum of group 1 x weighting) + (sum of group 2 x weighting).
In excel I use 2 tables to calculate, but struggling to figure this out in powerbi so far
I am currently using PowerBi to create Averages of scores per supplier.
I am now trying to moved towards weighted totals and weighted averages.
In my scenario I have
8 Divisions
22 Groups (of suppliers ie. Joint Ventures, multiple Suppliers working on a contract)
8 Individual Suppliers made up of a percentage of a group of suppliers.
Within Excel, I have created a supplier list 1-8 which uses a sum if from another table.
SUMIFS('Group Totals (Per)'!F:F,'Group Totals (Per)'!$B:$B,$B2)
This other table is a sumif of group name, division multiplied by weighting (percentage of the contract)
=SUM(SUMIFS(Payments!$I:$I,Payments!$C:$C,'Group Totals'!$A7,Payments!$B:$B,'Group Totals'!F$1)*$C7)
My hope is to replicate this within power BI.
So I can click select a supplier and see the total payments received (which will be a sum of a percentage of the group contract (joint ventures).
However I have been unable to separate out the suppliers totals with weighting, after creating links tables.
I have supplied sample data in excel and power BI and screenshots.
Here's a link! to the files.

SUMX is similar to SUMIF in Excel. But I would recommend you using CALCULATE function which gives you lot of options. A simple google will give you a lot of tutorials on how to use it.

Related

Create measure for % of Sales in Power bi

I am trying to create a % of sales measure in power bi. I currently have a visual that is filtered on sales for select items by day and another visual that just has the total sales by day and then I export and do the math in excel. I know there is a way to have just one visual give me the % of sales for the items I have selected, but can't figure out the DAX formula. I am looking for the formula that will take sales for item 1 on Monday of $3,461 and divide by total sales for Monday of $163,534 to get a 2.1% of sales (for all items). Thanks
Power Bi Visuals
I tried a couple formulas but was unsuccessful..
The December release of PBI has been pushed out to all users, and it comes with a brand-new WINDOW function. This allows you to create calculations that would be relative to data being displayed in the visualization rather than applying across an entire table.
Some things you can do with this type of DAX calculation:
Moving averages
Can also combine with parameters for additional functionality!
Dynamic reference lines
Cross row calculations
Finding best and worst performers (with ABS references)
Calculate contributions to the whole
Relevant links:
https://www.youtube.com/watch?v=eib5X5xRlz8
Introducing DAX Window Functions (Part 1) – pbidax (wordpress.com)
WINDOW – DAX Guide

Add missing month rows based on multiple columns with multiple variables in Power BI

I'm very stuck and I was hoping you can help. So have the following dataset (Table 1) with Month (5 years worth), Customer (1000 customers), Product (100 products), Units and Value (value is just unit multiple a price). The data only shows rows with unit and value, so for customers when there is no sale in a month, there is no data.
Click here for Table 1
I want to create a table (Table 2) where every product for every customer is shown for all time periods, where actual units and values are included and those missing in Table 1 are now showing 0.
Click here for Table 2
I have read many posts here and elsewhere, which only handles 1 column (e.g. only Customer not both Customer AND Product, and only 1 measure not Unit and Value). I tried to adapt the code but failed miserably.
I also want to do this in Power BI using M not DAX, because I would like to further transform the data.
Thank you so much everyone!!!
Good afternoon.
You can use DAX to create a calendar for the required period of time.
Use the minimum and maximum values from Table 1 for the interval (Calendar function).
Calendar = CALENDAR(Date(2022,5,1), TODAY() -1)
Link the calendar to the necessary dates.
calendar link example
In the settings of the table to which you will output data, select the "Show items without data" setting, and take the date from the calendar.

Add customizable date range comparisons to a Power BI Table

I am trying to recreate a Tableau table view in Power BI where I can compare two customizable date ranges and show the percent differences across metrics as a calculated row.
Reference Screenshot from Tableau
In practice, my table will have 3 rows: 1 row for each time period selected and a row for the percent difference. The percent difference row is a nice to have, not a need. All my table metrics are coming from the same source.
I also need to set up two different date slicers that each row of my table will reference. I've played around a little with setting up a separate date table for the comparison period to be selected from, following this thread: Comparing Data Across Date Ranges
The challenge now is showing two separate periods in the same table.
Appreciate any guidance!

Generate dynamic time representation using DAX

I am relatively new to PowerBI and struggling to accomplish the following task.
I have in total 3 Tables. 2 Tables are available and the 3rd is the outcome I am interested in.
Table 1 is a lookup table with yearly values for each option of a certain property.
Table 2 is a user input table containing the project list with a property that can be equal to one of the options in Table 1.
I am mostly interested in Mapping the projects with their yearly development based on one property. The outcome is represented in Table 3.
At the end of the day, I would like to plot the Sum across all projects against the year column (The 2 columns in red).
I hope someone can help here in finding the appropriate DAX logic. Thanks in advance!
You can bring the tables into a Power BI model, and from the modeling tab you can create relationships to accomplish this. Let me know if this is helpful.

Power BI DAX Cannot display correct monthly of last year's figures in a Matrix visual

I have a "strange" problem in visualizing the values of the "last" year (that is the most current year with data of a full year). In the example delivered it is 2019 which holds the bookings facts. The year should be derived by a related table (LetztesVollesJahrDim) that holds a min/max date and year value for each company/entity. The DateDim table holds all dates and is configured to be the Date dimension. 
The relations are shown in the graphic below.
I created a Report that should display different matrix tables with different values:
one, that shows the last full year's monthly values by Cost Center (which works correct)
one, that shows all years monthly values including an estimated value for the current year (2020) (which also works correct)
one, that could drill down to the details level of the Facts and display the figures per month (in columns) of the last full year (i.e. 2019) putting the Cost Center and other groups down the most detailed level into rows. This Matrix makes use of Calculated Measures created with Tabular Editor.
At this point I can here you say... try it without the Calculated measures and indeed I did that by simply displaying a Card that got a Visual Filter to DateDim[M]=7 to simulate the appliance of each matrix's column. Problem is the same: The Month filter of the Visual (or within the Calculated Measure) is ignored and the yearly sum is displayed (~48k) which is wrong.
As I am currently an Expert in SQL Server DBMS but not in the Architecture of Power BI's DAX Models I am not truely aware about the consequences when and why filters are removed, ignored, overwritten or added at which level of modeling.
Originally I tried to create a simple Calculated Measure that reflects the last full year of the company. That works, but its usage in the huge Matrix was impossible as it was calculating forever. That's why I created the simple table "LetztesVollesJahrDim" to hold a persisted value for each company.
The idea is simple: Create a Query that inner joins these tables and display the Sum for each month [M] like this:
Fact[Turnover] - Fact[CompanyKey] -> CompanyDim[CompanyKey] <-> LastFullYear[CompanyKey] - LastFullYear[MostCurrentYear] -> DateDim[Y] - DateDim[DateKey] -> Fact[StapleDateKey]
So, what is the Problem?
I tried a couple of DAX queries and all come up with a different wrong value.
Following three different approaches for a Calculated Measure "Sum LY":
1. 
Σ LY = CALCULATE(SUM(KontobuchungenFact[UmsatzNegiert]), DATESBETWEEN(DateDim[DateKey], DATE(2019, 1, 1), DATE(2019, 12,31)))
2. 
Σ LY = CALCULATE(SUM(KontobuchungenFact[UmsatzNegiert]), SAMEPERIODLASTYEAR(DateDim[DateKey]))
[
3. 
Σ LY = CALCULATE(SUM(KontobuchungenFact[UmsatzNegiert]), KEEPFILTERS(DateDim[M]), USERELATIONSHIP(DateDim[J], LetztesVollesJahrDim[AktuellstesJahr]), USERELATIONSHIP(DateDim[DateKey], KontobuchungenFact[StapelDateKey]))
 
Filters being applied on the page/visual:
CompanyKey
DateKey >= 2018-01-01 (page filter that limits the displayed rows in yearly matrix to the last 3 ys)
Some other irrelevant keys
Visual configuration:
Relations:
Values/Rows in the LetztesVollesJahrDim table:
Calculated Measures/Table in Tabular Editor showing the calculation of the "01 Jan" column of the first Matrix, which displays correct results:
Impression of the Report:
So in summary I need a clue/DAX formula that recognizes the Monthes in each column and ideally uses the relations to the last year table trespassing the year's filter through DateDim to the Facts.
It is funny, that the upper matrix works, but not the one on the bottom. It is not possible to use the calculated measures approach of the first matrix in the last matrix because the performance would drop to > minutes calculation. So I cannot use the same approach and need a fast one.
Anybody an idea? :-)