In Power BI I have a list of inventory transactions (InventTrans) with date, quantity and value for movements in and out of the inventory.
There are 1 million lines of inventory transactions, and the sum of all lines for each ItemID gives the inventory value of that item.
I have created a measure to calculate number of days from last movement until today:
Days since last movement = DATEDIFF(CALCULATE(MAX(InventTrans[Date]),TODAY(),DAY)
and a measure (InventoryStatus) to group each ItemID based on this result.
I have used
InventoryStatus = IF([Days since last movement]<183, "Movement last six months", ("Six months to a year", "Over 1 year". and so on)
Now I want to create a table with ItemID and the measure InventoryStatus.
My aim is to use InventoryStatus as a filter, so maybe there is better way to achieve this without creating a new table with ItemID and InventoryStatus.
Assuming inventory status is a property of the item, not the transaction, your proposed approach is probably correct. The data model will be more intuitive and more efficient if you create an items table that has ItemID, InventoryStatus, and any other item-level data. After linking the two tables together InventoryStatus can be used as a filter for transactions.
Related
I'm practicing my Power BI skills. I've downloaded a csv file which contains data about olympic games. The dataset has many columns, such as country, athlete name, year, sport, event, medal which the athlete has won, olympic city, etc.
The problem is that I want to create a bar graph that display country name by medal types count. However if create a graph "Country" by "Medal" from original csv it will not display the correct numbers of medals, because if a country wins a medal in a team sport (like volleyball or football) it should count as only one medal, and not the sum of all medals of all athletes in that team. This could be solved by removing Athlete column and selecting distinct values of "Event" column, like creating a table using the following formula:
Table 2 = CALCULATETABLE(ALLEXCEPT('summer (3)','summer (3)'[Athlete]),DISTINCT('summer (3)'[Event]))
However, I don't want to create a new table, because I would have serious problems with relationship between them (I have no idea how to do it, to be honest). So I want to create a measure. I created the following measure:
Medal count = COUNTX(CALCULATETABLE(ALLEXCEPT('summer (3)','summer (3)'[Athlete]),DISTINCT('summer (3)'[Event])),'summer (3)'[Medal])
It is showing the correct number of all medals in olympic games history (untill 2012). However, for every country, its showing the number of gold medal, silver medal and bronze medal with the same number (the total number of olympic medals 14753). It's not filtering by the number of rows for that specific country.
The same number also appears if I select any medal type from filter option (Gold, Silver or Bronze).
I have no idea how to fix this. How can I create a measure that shows the correct number of medal type for every country?
This is what I would do. First I will create an "id" column if I haven't had that, then I will do the distinctcount on that.
The DAX for the id column should be something like this:
debug_id = CONCATENATE(Table['Year'],CONCATENATE(Table['Sport'],CONCATENATE(Table['Discipline'],CONCATENATE(Table['Country'],CONCATENATE(Table['Event'],Table['Medal'])))))
then you can basically drag and drop this field onto the x-axis (y-axis and legends stay the same) and select Count (Distinct). If you really want the measure for this, it should be quite straight forward like:
Medals count = DISTINCTCOUNT(Table['debug_id'])
I'm trying to create a line chart in Power BI with two lines representing counts by date. The data is pulled from a single data table. I am trying to show two lines, one representing an incoming count and one representing an outgoing count. Each record has a unique identifier (IN). So, the chart would have months on the x-axis pulled from a date table I created. One line would show the count of incoming IN for each month, and the other line would show the count of outgoing IN for each month. When I try to do this, both lines show the same count. I've tried a number of different measures, but nothing seems to work. These are the latest that I'm trying.
Intake by Date = CALCULATE(DISTINCTCOUNT('sysadm kennel (2)'[impound_no]),'sysadm kennel (2)'[intake_date])
Outcome by Date = CALCULATE(DISTINCTCOUNT('sysadm kennel (2)'[impound_no]),'sysadm kennel (2)'[outcome_date])
I'm pretty new to Power BI, so I don't have a full grasp of how to create measures. The Intake By Date seems to be the correct one, but the Outcome by Date is showing the same number. Any help would be appreciated.
Check your model. Create an active relationship between Calendar and DataTable to your Intake; Add an inactive relationship between Calendar and DataTable to your Outcome; In measure for [Outcome by Date] use USERELATIONSHIP('Calendar'[Date],DataTable[OutcomeDate])
https://dax.guide/userelationship/
I have two tables which have counts and sales based on dates and one of them also have customer ID. The counts are not same when we see by customer and summary. I also have customer filter on my dashboard. What I want to achieve is if no customer is selected the count should come from summary table otherwise it should come from customer if multiple or one is selected in the filter.
Customer Table
Summary Table
Any hints, I have tried lookupvalue function but I cant put date as search value from date table.
It's much easier to use Measures, instead of creating calculated tables to obtain those metrics. Also, summarized tables would not have the same filter context your are looking for.
Measure 1
Total Customers =
DISTINCTCOUNT('Customer Table'[CustomerID])
Measure 2
Total Sales =
SUM ( 'Customer Table'[Sales])
I have merged two tabels ( sales and forecast ). For all the rows coming from sales query the cost price column has a value. The forecast rows does not have that.
In order to calculate future metrics/KPI I need to make a Power Query transformation that populates cost price on all forecast rows. I would like to do some kind of refence to the ProductName (exits both on the sales and forecast rows) and pull the cost price from the sales rows. The ProductName can have multiple entries in the table, but will be the same for alle the rows. So maybe a find first/max or something would be fine.
However, I am not sure have to make this calcuated column with some sort of lookup to ProductName?
Well you can definitely do so
Here is an excellent Article form Microsoft on LookupValue
In addition check this Thread as well. It will give you more Idea.
I would do something like
=LOOKUPVALUE(Product[SafetyStockLevel], [ProductName], " Mountain-400-W Silver, 46")
I have data from multiple countries on a monthly basis. Since the updates are not regular, I want to set up filter to visuals, so they would show the last month for which I have data from all the countries. I have data from each country loaded into a separate dataset, which then are merged into one big. Is there an easy way to place such filter? I managed to use "LASTDATE" function in each of country sets to find which date is last, but if I try to filter with that measure, I simply get nothing in a result. Thanks!
Well, this feels a little clunky to me but I believe it will work for you. There are two steps. The first is to create a summary table that reads through your data and counts the number of distinct countries that you have in each month. This will be a new table in your model, so go into the modeling tab, click 'New Table' and add this DAX. Obviously, correct for your table and column names.
SUMMARIZED_ROWS = SUMMARIZE(
'Table1'
,Table1[Month]
,"CountOfCountries"
,DISTINCTCOUNT(Table1[Country])
)
Now add a measure to the table (or anywhere) like this:
MonthWithMostCountries = CALCULATE(
LASTNONBLANK(SUMMARIZED_ROWS[Month], 1 )
, FILTER(SUMMARIZED_ROWS, SUMMARIZED_ROWS[CountOfCountries] = MAX(SUMMARIZED_ROWS[CountOfCountries]) ) )
This is going to give you the month where you have the most distinct countries in your data. You'll want to look at it in a card or similarly isolated visual as it is a measure and can be affected by filter context.
So, on the left is my mock data - 3 countries, 3 months each with a 1 month stagger. On the right you see the result of the Summarize table. Then the measure showing the final result.
Hope it helps.