Does anyone know what DAX function I should use to display information from one table in another table.
I've got 2 tables in my data model:
Tasks
- Task ID
- Task Name
- Start Date
- End Date
Fiscal Periods
- ID
- Period Name
- Start Date
- End Date
What I'm trying to do is for each Task, add a calculated column the is populated with the corresponding Fiscal Period ID. I'm trying to add a filter or calculation that specifies:
- if the task start date is between Fiscal Start Date and Fiscal End Date, return the fiscal period id.
Anyone have any ideas?
Thanks,
Ro
This might help:
In case Fiscal Period ID is a number:
=CALCULATE(MAX(Periods[ID]),FILTER(Periods,Periods[Start Date]<=Tasks[Start Date] && Periods[End Date]>=Tasks[Start Date]))
In case Fiscal Period ID is not a number:
Put Start Date to calculated column first, say 'Period Start Date'
=CALCULATE(MAX(Periods[Start Date]),FILTER(Periods,Periods[Start Date]<=Tasks[Start Date] && Periods[End Date]>=Tasks[Start Date]))
and then use LOOKUPVALUE for ID
=LOOKUPVALUE(Periods[ID],Periods[Start Date],Tasks[Period Start Date])
Related
How would I make the usage start date the current date - 2 days, and have the timestamp of the start date include between 00:00:000 and 23:59:59.999? I have to use LIKE and % since usually the timestamp includes the year, month, day but I don't want to have to insert that each time I run this.
WHERE line_item_usage_start_date = current_date - interval '2' day
AND line_item_usage_start_date BETWEEN(LIKE(TIMESTAMP '%00:00:00.000%' and TIMESTAMP '%2020-08-25 23:59:59.999%)';
If I understand correctly, line_item_usage_start_date is of type timestamp and you want to get all rows that fall somewhere between the beginning of the day and the end of the day two days ago. In that case, there are a couple of ways to go about this:
You can convert the timestamp to a date by casting and then match it against the date two days ago:
WHERE cast(line_item_usage_start_date AS DATE) = current_date - INTERVAL '2' DAY
Use current_timestamp and date_trunc to compute the timestamp corresponding to the beginning of the day and constrain your results to the range between the beginning of the day 2 days ago and the beginning of the day 1 day ago:
WHERE line_item_usage_start_date >= date_trunc('day', current_timestamp - INTERVAL '2' DAY) AND
line_item_usage_start_date < date_trunc('day', current_timestamp - INTERVAL '1' DAY)
My Data is in weekly buckets. I want to split the number into a monthly number but, since there is an overlap in days falling in both the months, I want a weighted average of the data in terms of days that fall in each of the months. For example:
Now, in the above picture, I want to split that 200 (5/7*200 in Jan, 2/7 in Feb). How can I do that using Excel/ Power Pivot/ Dax Functions? Any help here is much appreciated.
Thank you!
Assuming your fact table looks something like below. Values are associated with the starting date of the week it occurred.
Although it may actually be a more granular data, having multiple rows for each week with additional attributes (such as identifiers of a person, a store, depending on the business), what being shown below will work the same.
What we need to do first is to create a date table. We can do that in "Design" tab, by clicking "Date Table", then "New".
In this date table, we need to add a column for starting date of the week which the date of each row is in. Set the cursor to "Add Column" area, and input following formula. Then rename this column to "Week Start Date".
= [Date] - [Day Of Week Number] + 1
Now, we can define the measure to calculate the number allocated to each month with following formula. What this measure is doing is:
Iterating over each row of the fact table
Count the number of days for the week visible in the filter context
Add the value portion for the visible days
Value Allocation := SUMX (
MyData,
VAR WeekStartDate = MyData[Week]
VAR NumDaysInSelection = COUNTROWS (
FILTER (
'Calendar',
'Calendar'[Week Start Date] = WeekStartDate
)
)
VAR AllocationRate = DIVIDE ( NumDaysInSelection, 7 )
RETURN AllocationRate * MyData[Value]
)
Result in the pivot table will be looking like this.
I am trying to create a measure that will sum invoices totals for all assets but exclude assets whose contracts have expired. The tables look something like this:
Service Data:
Invoice Amount
Asset Key
Invoice Date
Asset Data:
Asset Key
Contract Start Date
Contract End Date
I am also using a date table that is attached to a slicer on the main page of my dashboard. I would like to be able to select a date range on the slicer and have it limit which assets' invoices in includes in the total in respect to the date range selected on the slicer.
Here is what I was attempting so far:
NewISA =
var enddate = MIN(F_Service_Invoice_Summary[Invoice_Date])
Return
IF(
enddate <= F_Asset[End_Date],
SUM(F_Service_Invoice_Summary[Invoice_Segment_Amount]),
0)
Assuming you have a relationship between the ServiceData and AssetData on the AssetKey field and that you have a relationship between your DateTable and ServiceData table on the InvoiceDate field, the following formula should work:
Total Invoiced Active Contracts =
CALCULATE (
SUM ( ServiceData[Invoice Amount] ),
FILTER (
AssetData,
AssetData[Contract Start Date] <= MIN ( DateTable[Date] )
&& AssetData[Contract EndDate] > MAX ( DateTable[Date] )
)
)
We can use MIN(datetable[date]) and MAX(datetable[date]) to determine the interval that is filtered in the datetable to only select contracts that are active during the whole period. Please keep in mind that if you do not select an interval, the formula will only return contracts that started before the first date in your datetable and end after the last date in your datetable.
I have 2 dates one is stored inside my date and for other date I am using calculated column in order to store the end date into that, how an I calculate the difference in time period between those dates, I need the date period between all those dates is that possible with DAX?
How can I use calculated column inside my DAX and also I dont have a calender table inside my database.
2019-05-31 and end date is 2019-06-03 then the difference will give me 3 dates that is 2019-05-31,2019-06-01 2019-06-02 and 2019-06-03
Totally possible and easy. If you just need the difference between dates in two columns you can create a calculated column using the following:
DateDiff =
DATEDIFF ( 'Table'[Date1], 'Table'[Date2], DAY )
This will take the difference between Date1 and Date2 in days.
DECLARE #start_date [date] = CAST(‘2012-08-01’ as [date])
DECLARE #end_date [date] = CAST(‘2012-09-01’ as [date])
SELECT
DATEADD(day, [v].[number], #start_date)
FROM
[master].[dbo].[spt_values] [v]
WHERE
[v].[type] = ‘P’ AND
DATEADD(day, [v].[number], #start_date) <= #end_date
I have a dataset that exports all actions by a candidate appointment database, but as the candidate can be booked for more than one appointment all I want to check is the candidate has attended one appointment within the given month.
Currently I use the below formula:
=SUM(COUNTIFS(ActionsImport[Activity Type], "Appointment*", ActionsImport[Status/Outcome], "Attended", ActionsImport[Activity Date], ">="&AS2, ActionsImport[Activity Date], "<="&AZ2))
ActionsImport[Activity Type] - Is to look for all Appointments
ActionsImport[Status/Outcome] - Is if they have attended
ActionsImport[Activity Date] - Is the start and end date range
I also have ActionsImport[Candidate ID] that I can use as a unique identifier, but I'm not sure how I would go about creating the unique search. I have been looking into SUMPRODUCT and FREQUENCY, but without much luck.