Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
ToniT
Frequent Visitor

Context issue when displaying prior year total that is based on date and category

My goal is to create a table that shows total applicants by action status for both selected and prior periods using the status that they had as of a selected date AND admission term. In other words, I want to count the students under the status for the row that is the the max effective dated row that is less than or equal to the selected date. I was able to do it for the selected values, but I'm having trouble showing the prior year in the same visual. 

 

My data set is a list of student applications and their statuses (sample below). Each student has multiple rows of data that are effective dated but also have a sequence number in case 2 transactions happen on the same day. 

 

What works: I have a measure that correctly calculates the number of applicants in each status as of the Admit Term and Date selected. I have also created a second measure based on this to calculate the prior year by finding that from the selected values (below). This measure appears to return the correct value when I EVALUATE it in DAX Query. If I return the variables as the output for the measure, they select the correct values. For example, if I select Fall 2024 and return _lastTerm, the measure returns Fall 2023.

 

Not Working: When I place both these measures in a visual together, the prior year shows up blank. I’m sure that this is a context issue, but can’t figure out how to fix this.

 

Any help will be appreciated.

 

Desired output is to show the corresponding counts for selected and prior Term/Date combination.

ToniT_0-1722280944865.png

 

Measure (note: current year uses same measure but without the "last" variables)

Applicant Status Prior Year =
var _selectedDate = DATEVALUE(MAX('DimDate'[CalendarDate]))        //get slicer value for effective date
var _selectedTerm = SELECTEDVALUE('Application data'[AdmitTermCode])   //get slicer value for Admit Term
var _selectedTermSeason = SELECTEDVALUE('Application data'[TermSeason]) //get associated Term Season
var _lastyear =                                              //calculate same day last year
    CALCULATE(
        MAX('DimDate'[CalendarDate]),
        SAMEPERIODLASTYEAR('DimDate'[CalendarDate]))      

var _lastTerm = CALCULATE(MAX('DimTerm'[TermCode])                 //get term code from last year
            , ALL('DimTerm')
                , 'DimTerm'[TermCode] < _selectedTerm
                , 'DimTerm'[TermSeason] = _selectedTermSeason)

--filter app data to only row for selected term and before selected date
var _onlyBeforeDate =                                  
        SUMMARIZE(
            FILTER(ALL('Application data')
                ,   'Application data'[AdmitTermCode] = _lastTerm  
                && 'Application data'[EffectiveDate] <= _lastyear)  
        , 'Application data'[StudentNumber]
        , 'Application data'[z_PartitionKey]
        , 'Application data'[AppSequence])  
       
-- Determine the most recent row before the selected date for each application
var _maxEffectiveDate =
        INDEX(1
            , _onlyBeforeDate
            , ORDERBY('Application data'[AppSequence], DESC)
            , PARTITIONBY('Application data'[z_PartitionKey]))

return CALCULATE(DISTINCTCOUNT('Application data'[StudentNumber]),   _maxEffectiveDate)
 
Model:
ToniT_2-1722282519153.png

 


 

Example of Data:
Note that multiple admit terms are accepting applications on any given calendar date, so date can't be the only value used to define the current/prior periods.
 
StudentNumberApplicationNumberAdmitTermCodeTermSeasonAppSequencez_PartitionKeyEffectiveDateProgramActionCode
1234565604951241Fall1123456_5604952024-05-27 0:00APPL
1234565604951241Fall2123456_5604952024-05-28 0:00ADMT
1234565604951241Fall3123456_5604952024-06-03 0:00MATR
1234575589971241Fall1123457_5589972024-05-04 0:00APPL
1234575589971241Fall2123457_5589972024-05-05 0:00ADMT
1234575589971241Fall3123457_5589972024-05-17 0:00MATR
1234565045001231Fall1123463_5045002022-10-31 0:00APPL
1234565045001231Fall2123463_5045002023-02-01 0:00APPL
1234565045001231Fall3123463_5045002023-02-01 0:00ADMT

 

9 REPLIES 9
ToniT
Frequent Visitor

Hi, thanks for looking at this!

 

For ID 123456, if I select a term of 1241 and a date of 2024-06-01 this student is counted in the ‘current’ measure under the Action code of ADMT.  Based on the selection, the prior period would translate to term 1231 and a date of 2023-06-01, so I would expect to this application counted in the prior term also with a status of ADMT because that is the max row in the partition with the highest sequence number. My measures don’t use effective date because it is possible to have 2 transactions on the same day, so I ORDER the partition by the AppSequence number instead.

 

I don't have the ability to upload a file, but I do have a working .pbix example. I will try to get a link to it using Dropbox. 

 

In the meantime, the DimTerm dimension looks like this:

DimTerm[TermCode]DimTerm[AcademicYear]DimTerm[TermSeason]
12332023Spring
12312023Fall
12302023Summer
12322023Winter
12402024Summer
12422024Winter
12412024Fall
12432024Spring

Hi @ToniT I will take a look and let you know 🙂





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Hi @ToniT I am currently checking your file.

Did you notice that your slicer for CaledarDate is style "Before", so this mean it showing data before 2.5.2024 not exact date, so this could affect your logic and calculation.

 

In addition, do you really want result per date, like for same date previous year? If so, at least for example file, for AdminTermCode=1241 there are dates: min=28.12.2023  and max=17.07.2024, so if you filter any dates in year 2024 there is no same date for previous date (2023). This could mean that your measure works fines, eventually, but as there is not data for previous year same date, the blank is ok?

 

some_bih_0-1722491996643.png

 

AdminTermCode=1241

some_bih_1-1722493472145.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Thanks for looking at this.

 

I used Before in the slicer because when I choose a specific date I only select transactions that happened on that date, and not all the transactions that happened earlier in the admission cycle. In my data set, I want to count all applications that have any row before the selected date, but only count them once per application, and count them in the category (Action) associated with the row that is closest to the selected date.  

 

The measure called Applicant Status by Date works 100% correctly with this data set and interacts with the slicers properly. I just can’t also display Applicant Status Prior Year in the same visual. I don’t want to count every row for each application under every status, which looks like what  CountDistStN does in your example.

 

In the screenshot below, I’m able to achieve what I’m trying to do by including 2 different sets slicers and tables. I was hoping to display both in the same table so that users don’t have to select multiple times, but having done this, there may be value in allowing them to compare any two dates like this and not just prior year.

ToniT_0-1722526936376.png

 

Hi @ToniT ok for Before, I know more now.

So measure Applicant Status Prior Year, should show 

Same as measure Applicant Status by Date but  up to 1 year earlier?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Yes, that's it exactly!

Hi @ToniT ok.

I am tomorrrow one day out of office, but I will check it and let you know, start of next week the latest





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






some_bih
Super User
Super User

Hi @ToniT I tried to use your sample of data and reuse measure, but without success as in measure there is reference to table/s DimTerm etc.

For sure, model seems ok (star schema) which is good start for measures.

Nevertheless, I tried to figure out what is your request, no matter what is data. 

From your sample data, only (not other table/s) for StudentNumber = 123456 is it possible to get answer for your request? If yes please let me know what is expected output for your scenario.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Here is a link to an example .pbix file. dropbox for example 

 

For StudentNumbers can have multiple applications in multiple terms, but the z_PartitionKey and AppSequence fields will return distinct groupings and orders. 

 

thanks!

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.