datesbetween
28 Topicsmeasure with period join
Hi, I have 2 tables : - PRODUCT_VERSION : Product_id Product_version Start_date End_date A 1 01/01/2024 31/08/2024 A 2 01/09/2024 30/04/2025 A 3 01/05/2025 - PRODUCT_SALES : Product_id Sales Sales_date A 6 18/01/2024 A 24 21/09/2024 A 8 01/03/2025 I want to calculate the sales for each product version in the PRODUCT_VERSION table. I join the 2 tables on product_id and I create a measure : CALCULATE (sales,DATESBETWEEN(Sales_date,Start_date,End_date)) But it doesn't work, do you have an idea ?Solved572Views0likes5CommentsProblem with DATESBETWEEN that has a variable inside
Hi DAX gurus, I'm having some troubles making DAX run as intended, i've spent a couple of days of testing quite a few things and can't get it to work, worst part is that separately (debbuging) everything seems to work correctly. Dataset: I have 3 datasets that are being used. A MasterDatabase that has all the dimensions and measures, a DataTable that is generated our of MasterDatabase (and other, irrelevant datasets) that is linked with a 1 : * with MDB, and a Seasonality/liability dataset that is generated from MasterDB with a 1 : * connection and has a additional hierarchy columns Dashboard: Slicer based on date from the Datatable (linked to MasterDB), slicer based on Season from the seasonality dataset, table in which i have dimensions and calculated measures from MasterDatabase Intention: I would like for the user to be able to select the period range they want as the basis (ie: sales from 1st of Jan up to the 18th Aug). At the same time i need to have a measure that will hardcap the starting or ending dates based on the selected season. But let's do this part in two steps, i first need it to cap and not extend up to the max slicer range, if we get that going, in that case i will add a MIN(MAXX()) that will either take the hardcaped date or an earlier date if the slicer range comes up before that. (and MAX(MINX()) for the other way around. DAX: CapedMeasure = VAR StartDate = SWITCH( TRUE(), SELECTEDVALUE(LiabilityHCTable[Simplified Liability]) = "S22", DATE(2022, 01, 01), SELECTEDVALUE(LiabilityHCTable[Simplified Liability]) = "S23", DATE(2023, 01, 01), SELECTEDVALUE(LiabilityHCTable[Simplified Liability]) = "F22", DATE(2022, 07, 01) ) VAR EndDate = SWITCH( TRUE(), SELECTEDVALUE(LiabilityHCTable[Simplified Liability]) = "S22", DATE(2022, 06, 30), SELECTEDVALUE(LiabilityHCTable[Simplified Liability]) = "S23", DATE(2023, 06, 30), SELECTEDVALUE(LiabilityHCTable[Simplified Liability]) = "F22", DATE(2022, 12, 31) ) RETURN CALCULATE( SUM(MasterData[*Sales LC]), KEEPFILTERS( DATESBETWEEN( DateTable[Date], StartDate, EndDate ) ) Problem: The Dax works, but i don't get the intended result; let's suppose i selected S23 (spring 23), my measure should take all the sales from the 1st jan 23 up to the 30. june 23, but if in my slicer i go above that it will not cap at the 30th june mark and will take the max selected value from the slicer and sales from that whole range If instead of the variables i use DATE() with the same value, it works as intended, it's the combination under calcualte that seems to be the problem. I've tried SUMX(MasterData, MasterData[*Sales LC]), ALL(DateTable[Date]), DATESBETWEEN())) but to no avail (keeps extended range). and i've also tried: CALCULATE( SUM(MasterData[*Sales LC]), KEEPFILTERS( DATESBETWEEN( DateTable[Date], StartDate, EndDate ) ), REMOVEFILTERS(DateTable[Date]), and: CALCULATE( SUM(MasterData[*Sales LC]), ALL(DateTable[Date]), FILTER( DateTable, DateTable[Date] >= StartDate && DateTable[Date] <= EndDate ) but both return blank. Quite a few other solutions too (disconnected datetable as slicer selector, splitting the date var. in year, month, day, and injeting it as such in DATE() bellow the datesbetween etc), but the result ends up either blank or the whole selected slicer range. If anybody has an idea on how to make the above work, i'm all ears... 🙂Solved1.1KViews0likes6CommentsDAX Measure for No of Promotions for Last 12 Months Hires
Hi Community, I have a requirement to find the number of promotions given to people hired in the last 12 months. My Table Hire Date is connected with the Calendar table. If I select Month as September 2024, I am expecting to see the cumulative promotions from Oct 2023 to September 2024 for the people hired in the same period. As per my sample below it should be 18 Sample data given below. Any help would be highly appreciated. Person Number Promotion Date Hire Date 1 09-Apr-23 20-Mar-23 2 25-Aug-24 20-Mar-23 3 08-Oct-23 30-Aug-23 4 14-May-23 06-Jul-21 5 11-Feb-24 23-Sep-20 6 07-Jan-24 18-May-21 7 01-Sep-24 18-May-21 8 01-Oct-23 07-Feb-20 9 31-Mar-24 07-Feb-20 10 11-Feb-24 12-May-21 11 28-Apr-24 01-Apr-24 12 25-Aug-24 30-Jan-23 13 01-Jun-23 06-Feb-23 14 01-Jun-24 15-Aug-24 15 01-Sep-21 16-Mar-23 16 22-May-22 08-May-24 17 16-Oct-20 04-Jan-23 18 01-Sep-22 15-Mar-21 19 16-Apr-22 15-Mar-21 20 16-May-24 10-Nov-20 21 03-Dec-23 29-Nov-21 22 13-Aug-23 17-Mar-21 23 02-Apr-23 17-Mar-21 24 25-Feb-24 18-Oct-23 25 25-Aug-24 18-Oct-23 26 02-Apr-23 13-Feb-23 27 25-Feb-24 21-Aug-23 28 03-Mar-24 21-Aug-23 29 12-May-24 01-Apr-13 30 12-Feb-23 16-Dec-13 31 22-Oct-23 03-Jun-13 32 04-Feb-24 25-Jan-12 33 07-Jan-24 01-Feb-12 34 27-Aug-23 01-Apr-13 35 10-Dec-23 20-Sep-23 36 25-Aug-24 27-Jun-24 37 02-Jun-24 09-Jul-23 38 03-Sep-23 10-Apr-23 39 01-Oct-23 03-Apr-23 40 28-Mar-23 06-Feb-23 41 02-Sep-24 01-Jan-24 42 30-Sep-24 01-Jan-24 43 13-May-24 01-Jan-24 44 03-Sep-23 06-Jul-23 45 01-Apr-24 01-Jun-23 46 01-Oct-23 20-Apr-23 47 17-Jun-24 01-Jan-24 48 01-Aug-24 26-Apr-23 49 28-Apr-24 25-Jun-23 50 01-Aug-24 26-Apr-23 51 19-Nov-23 09-Jul-23 52 01-Oct-23 10-Apr-23 53 09-Jun-24 20-Aug-23 54 22-Sep-24 20-May-24 55 29-Apr-24 01-Jan-24 56 25-Feb-24 25-Sep-23 57 10-Dec-23 25-Sep-23 58 19-Feb-24 01-Jan-24 59 05-Aug-24 01-Jan-24 60 03-Mar-24 22-Jan-24 61 01-Jun-24 22-Jun-23 62 25-Aug-24 18-Jun-23 63 13-May-24 01-Jan-24 64 09-Jun-24 17-Sep-23 65 01-Oct-23 23-Apr-23 66 09-Jun-24 20-Aug-23 67 17-Jun-24 01-Jan-24 68 01-Jun-24 03-Apr-23 69 01-Aug-24 13-Mar-23 70 01-Apr-24 17-Jul-23 71 01-Jun-23 11-Jan-23 72 01-Sep-24 02-Jan-23 73 16-Aug-23 04-Jan-23 74 01-Oct-22 04-Dec-23 75 01-Jun-22 04-Jan-23 76 01-Nov-21 04-Jan-23 77 01-Aug-22 04-Jan-23 78 01-Jun-23 23-Jan-23 79 01-Apr-23 09-Jan-23 80 01-Dec-21 09-Jan-23 81 26-Feb-23 11-Jan-23 82 22-Apr-24 01-Jan-24 83 26-Feb-23 16-Jan-23 84 11-Jun-23 16-Jan-23 85 12-Feb-23 16-Jan-23 86 12-Mar-23 16-Jan-23 87 01-May-24 23-Jan-23 88 19-Mar-23 16-Jan-23 89 02-Jul-23 16-Apr-23 90 25-Aug-24 16-Apr-23 91 01-Jun-24 18-Jan-23 92 01-Oct-23 23-Jan-23 93 13-May-24 01-Jan-24 94 12-Feb-23 23-Jan-23 95 26-Feb-23 23-Jan-23 96 12-Feb-23 23-Jan-23 97 24-Sep-23 23-Jan-23 98 18-Feb-24 25-Jan-23 99 06-Aug-23 30-Jan-23 100 22-Oct-23 30-Jan-23Solved911Views0likes3CommentsCalculating quote ages
Hello, I have a data set with month and count of quotes. I need a measure that will calculate Count the number of quotes that are: current (1 - 4 months); 5 - 7 months old; 8 - 12months old and greater than 12 months old based off today's current month. An example of what I want is below. I will then put the measures into a bar chart to see the "age" of the quotes. TIASolved4.1KViews0likes2CommentsDATESBETWEEN is not working with min and max dates
I am trying to select a date (or several dates) in my slicer, and then use this to calculate a range of dates from 5 days prior to the earliest date selected to the max date in the slicer. For example, selecting 10th Feb in the slicer should give me a date range from 5th Feb to 10th Feb. I've created two calculated columns for these: MinDatePeriodMX = CALCULATE(min('Period A'[Day_Date])-5) MaxDatePeriodMX = CALCULATE(max('Period A'[Day_Date])) They seem to work as expected. However, I can't use them in conjunction with this formula: # Users - L13W MX = CALCULATE([# Users], DATESBETWEEN('Period A'[Day_Date], [MinDatePeriodMX], [MaxDatePeriodMX])) Instead of returning the # Users measure for only the dats in red below, it returns either only the date(s) in the slicer or if i disable interactions from the slicer, then it returns all dates there is data for. I only want the range of dates in the red box above. How do I achieve this? If I change the formula to "hardcode" the dates then it does work as expected: # Users - L13W = CALCULATE([# Users], DATESBETWEEN('Period A'[Day_Date], "2023-02-05", "2023-02-10")) Which makes me think that I'm missing some context somewhere. But I can't for the life of me work out where.1.9KViews0likes3CommentsUnable to select multiple values in slicer and pass to datesbetween function
Hi Everyone, I need help. I have a DAX measure which works fine with a single value selected in the slicer but when multiple values are selected this doesn't work as expected. Can someone please guide me? Thank you for the help Sales New Measure = VAR SlicerSelection = SELECTEDVALUE('Calendar'[DAY_OF_WEEK_NM]) RETURN IF(SlicerSelection=BLANK(),[Sales Dynamic],CALCULATE(sum(Purchase[Sales]), DATESBETWEEN('Calendar'[CALENDAR_DT], [Min Date], [Max Date]), 'Calendar'[DAY_OF_WEEK_NM] = SlicerSelection))Solved2.1KViews0likes5CommentsUsing MAXX and filter with dates from date slicer
I want the max value of a category. Which I have done successfully by using this Max = var fid = Table[category] return CALCULATE( MAXX( FILTER(Table, Table[category] = fid), Table[Value] ) ) But I want to be able to compare the dates in my table to the current selected dates from my slicer. As in, I only want Max to be the maximum value within the date range I have. How can I differentiate the current row's date from the min and max date slicer selection? I keep getting circular dependency errors. Date Category Value *What I want Max to be* 12/12/2022 franchise1 0 0 01/04/2022 franchise1 0 0 01/01/2017 franchise1 4 0 03/09/2022 franchise2 0 3 10/08/2022 franchise2 3 3Solved918Views0likes1CommentFind duplicates between "date selected" and "date selected" - 30 days
Hi! 🙂 I have date filters (slicer) for year, month and day in a model that uses a table with [ID] and [Date] I want to show the duplicates between the "Date selected" and ("Date selected" -30 days) This is the table: If i select "December 1st, 2022" it should only show these: Thank you!1.1KViews0likes3CommentsCount rows before date with a condition
Hi there, I'm having trouble adding another conditon to a DAX - to determine the number of voluntary leavers in a specified period. For all leavers, the DAX I'm using is: var mindate = calculate(min('Calendar'[Date]), ALL('Calendar'[Date])) var maxdate = calculate(max('Calendar'[Date]), ALLSELECTED('Calendar'[Date])) var cnt = CALCULATE(COUNTROWS(Master), DATESBETWEEN('Calendar'[Date], mindate, (maxdate+1)), USERELATIONSHIP('Calendar'[Date], Master[Termination Date])) return cnt) This works just fine. However, I'm not sure how to get the calculation to work when adding in one more criteria, which would be: Master[Turnover Reason] = "Voluntary" In Excel, the equivalent formula is a simple COUNTIFS: COUNTIFS(Master!E:E,"<"&$A$1,Master!J:J,"Voluntary") [where Column E is the termination date, A1 is the start date in the series and Column J is the termination reason] Any ideas on how I can expand the DAX to accomodate counting the number of termination dates that fall in (or before) a date range where I also have a criteria that only returns those wirh Voluntary termination? Below is a simple example of the raw data table Position ID Employee ID Name Hire Date Termination Date Employee Status Company Company Code Home Department Description Turnover Reason 1 1 Example Employee 1 14/12/2021 Active Company A A11 Sales 2 2 Example Employee 2 23/04/2021 Active Company A A11 Marketing 3 3 Example Employee 3 15/07/2021 Active Company A A11 Finance 4 4 Example Employee 4 04/11/2021 23/05/2022 Terminated Company A A11 HR Voluntary 5 5 Example Employee 5 16/11/2021 Active Company A A11 Legal 6 6 Example Employee 6 17/11/2021 Active Company A A11 Sales 7 7 Example Employee 7 23/04/2021 14/06/2022 Terminated Company A A11 Marketing Voluntary 8 8 Example Employee 8 02/08/2021 Active Company B B18 Finance 9 9 Example Employee 9 01/09/2021 Active Company B B18 HR 10 10 Example Employee 10 22/09/2021 Active Company B B18 LegalSolved2.9KViews0likes4CommentsHow to count working days between two dates within the same table
Hi everyone, I am attempting to create a measure per row which counts the working days between two days within the same table. To do that, I found the following guide: https://blog.enterprisedna.co/calculate-workdays-between-two-dates-in-power-bi/ However, when I follow it, I get the error message "A single value for column 'DateOfDelivery' in table 'Deliveries' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.". Unfortunately, I am unsure how to address this problem adequately. The way I see it, there is always just one 'DateOfDelivery' per row so I do not understand how this single value cannot be determined per row. Here is the table that I am using: Here, it is possible that one order may result in several deliveries. And this is my date table: I am using the following DAX expression: PassedDays1 = CALCULATE( COUNTROWS('Date'), DATESBETWEEN( 'Date'[Date], Deliveries[DateOfDelivery], Deliveries[OrderDate] ), 'Date'[IsWeekday] = TRUE ) Does anyone know what/where my error is?Solved924Views0likes2Comments