Measure for filling in blanks between two tables - powerbi

tried to figure this one myself to no luck and couldn't find similar problem through Google.
I have a number of tables within PowerBI dashboard, one table is a stock table that has values for random dates throughout the month, what i am trying to figure out is, how can i use dates from DayDim table(that has all dates for a month) in a table view and have a measure that would fill in missing dates with the most recent value from the stock table.
Please see a simplified representation as per image attached.
Of course in that stock table i have numerous products and customers etc. for each of those dates, so i would need to have the ability to still calculate values within those contexts, rather than just a total value number.
any help greatly appreciated, thank you in advance.

If you realy need this you can go with an extra column on your Day Dim table (or create a new table).
Value = LOOKUPVALUE(stock[Value];stock[Stock Date];
CALCULATE(MAX('Day Dim Table'[Date]);
FILTER('Day Dim Table';'Day Dim Table'[Date] <=EARLIER('Day Dim Table'[Date]) && RELATED(stock[Value]) <> BLANK())))
Please ensure you create a relation on date between the 2 tables.
I do wonder why you need it because I do not see the point of creating extra data but then again, I do not know your requirements..

Related

Creating a summarizecolumns filling blank data with zero

I'm kind of new with DAX and I'm currently stuck with a problem.
I have two tables Fiscal Calendar and Customer. I created a relationship using the date columns from both table.
The customer table contains records and I would like to show on a matrix if a record exist or not on specific dates (or fiscal weeks) like in the image below.
I made a summarizecolumns table (see the dax sentence below) however, what I need is if the record doesn't exist on specific date/week, I want to fill it with zero value instead of having it just blank. I tried many things already but until now I couldn't find any solution. If anyone is willing to help me I would really appreciate it.
Adherence =
var customerNames = VALUES(Customer[CUST_NAME_EXT])
var customerNumber = VALUES(Customer[CUSTOMER_EXT])
var selectedDates = VALUES('Fiscal Calendar'[fiscalDate])
var filterCustomerNames = FILTER(Customer,Customer[CUST_NAME_EXT] in (customerNames))
var filteDates = FILTER('Fiscal Calendar', 'Fiscal Calendar'[fiscalDate] in selectedDates)
var filterCustNumber = FILTER(Customer, Customer[CUSTOMER_EXT] in customerNumber)
var t = SUMMARIZECOLUMNS(Customer[CUST_NAME_EXT],Customer[CUSTOMER_EXT],'Fiscal Calendar'[fiscalYear],'Fiscal Calendar'[fiscalWeek], filterCustNumber ,"isAvailable", 1)
return t
First, I want to give you kudos for using SUMMARIZECOLUMNS. If I understand you correctly, you were trying to write DAX as if it is an SQL query, but it is not the case. To know the difference between them, you can read my answer to {How to write SQL in DAX?} question using this link:
How to write SQL in DAX?
Still, you can do it more easily by using the Power BI modeling strength because you said you had created a relationship using the date columns from both tables, Fiscal Calendar and Customer.
Second, to achieve your requirement, you need to create a flag to show 1 if a customer exists on a date or week and 0 if not, which, thankfully, can be implemented for any segregation level (columns) in your Fiscal Calendar table, just by two simple measures, which are as follows:
Count Rows = COUNTROWS(Customer)
Adherence = IF(ISBLANK([Count Rows]),0,1)
Finally, as your image shows, you will use the simple Adherence measure to give you the needed result.
In the end, I want to give you a helpful tip; I see you are trying to create a custom heat map using the Power BI matrix, which is very cool. Please use this link as a reference for more design ideas for what you are trying to achieve. The link is:
https://sqlskull.com/2020/12/17/implementing-a-table-heat-map-in-power-bi/#:~:text=A%20Heat%20map%20is%20used%20to%20visualize%20the,to%20apply%20some%20conditional%20formatting%20in%20matrix%20table.
I hope I helped in a way; if so, please mark this as an answer and vote for it :)

Change X axis date range start point depending on user selection

So for the purposes of this quandry, I have two tables in Power BI desktop. A 'Finance' and a 'Calendar' table.
The Calendar table has a filter (towards) relationship with 'Finance.' They are joined on Finance[Transaction date] = Calendar[date].
Finance contains transactions from individuals, there might be multiple for each individual.
I want to know how I can display a count of transactions by year for a selected individual (or individuals) from the 'Finance' table on a bar graph axis in a way that the dates start at the point of their first transaction, rather than the first date in the calendar table.
I'm open to changing the model, so any way of achieving this independent of my current setup is welcome. Any help much appreciated.
Im not quite sure this is what you are looking ,
If you want to show numbers on your whatever visualization you can add it from here
it displays numbers accordingly

How to create a measure that takes part of column?

I load a monthly data from a text file every month. In the table, there is a column that has string values with some extra strings with a fixed length. So the column looks like the following:
**OriginalColumn**
String1_XXXXX
String2_XXXXX
...
StringN_XXXXX
I would like to get rid of this extra fixed length string from the original column and I can do that by creating a new column something like:
NewColumn = LEFT(OriginalColumn,LEN(OriginalColumn)-6)
I am looking for a way to create a measure instead of a column. This is because as this is a monthly process that I would like to reduce the manual operation every month to create a new column. If using a measure, only data can be replaced.
Is there any way to do that? I have not found a measure that is working. When I create a measure I always need to wrap a column that has string values with some function such as MAX(SomeColumn). I always thought there should be a better way.
Would somebody kindly advise?
Thanks & Regards,
Kyoto
No need for a calculated column or a new measure, this can be done in a power query editor to remove the fixed length string from the original column before loading it into your model.

Power BI Table w/ Slicer Where Other Columns Adjust Parameters Based Off Selection

I have the following Power BI table example for an operating expense report that uses a slicer to filter the first column named "Actual". This is to see the operating expenses for one month compared to the budget figures for the year. It also compares the year-to-date and annual figures. How can I create dynamic columns that change based on the slicer selection? These additional columns are not shown in the pic below but included in the last pic. The Budget column below was just created as an example to show what it should look like.
I set up a star schema with several tables shown below. There's only one expense fact table used and the slicer only works for the first column as previously stated but I need all the other columns to use different parameters and adjust based off what's selected in the slicer. The last image is an overview of the info and the parameters for each column. I tried creating new columns with measures for the budget to see if I can get that going but can't figure out how to make it adjust with the slicer selection.
I'm not sure if I should be using separate queries for each column or can this be done using the one expense table. Hope this isn't too confusing. Please let me know if more info is needed.
If I understood what you wanted correctly I think I solved your problem.
I was able to create the following:
I did not use all values since I did not want to type everything, if you provide some test data it is easier to replicate you dashboard.
This matrix (so not table) allows you to filter for Date (if you so desire, you can always show all date's in the matrix) Book and AccountTree.
The way this is done is by putting the address column in the ROWS for the matrix, Putting the Date column in the COLUMNS of the matrix and putting your values (actual, budget, variance) in the values of the matrix.
For the date is used days, since it was easier to type. You can always use weeks, months, quarters or years.
For this to work you have to create the following relationships:
Hope this helps.
If not, please provide test data so it is easier to try and solve your problem.

Power BI visualization of data with a Start and End date

THis is an example of what I think i need to do
I would like to ask some modeling advise I cannot solve myself:
I am using Power BI to visualize the time machinery is out of order.
The source is a register of equipment not functioning, with a start date and end date (note that there is no end date if the machine is not fixed yet).
I would like to show the time (hours, percentage, etc) that the machinery is out of order, filter for a specific period /date (e.g. month).
So I have 2 date columns: ‘’Start out of order’’ and ‘’Back in order’’
I do have a date table, which I usually would connect to all the date variables. However, since I am working with a Start and End date. This does not give the result I am looking for.
Any help is very much appreciated!
Kind regards,
Link to my Power BI FILE:
https://wetransfer.com/downloads/83ca3850392967d0d42a5cc71f4352c420200213160932/eb7353
Stijn
I am not sure how you would like to visualise your data, but this is what I managed to do:
create a daysdiff column with
Daysbetween = IF(ISBLANK(TF_Eventos
[End out of order]);DATEDIFF(TF_Eventos[Start out of
order];TF_Eventos[TODAY];HOUR);DATEDIFF(TF_Eventos
[Start out of order];TF_Eventos[End out of order];HOUR))
This creates your column to check difference between Dates.
Then create a separate column with your Date. In this case I copied the Start out of order date, since I thought you might wanted to be able to filter for the start dates. Then simply create a relationship between your newly created Date column and your start out of order date.
Doing so lets you create a visual with the daysbetween (in this case portrayed in hours) and your start dates. Now just simply add a slicer and you can filter on date.
Hope this helps