cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kuraitengai
Frequent Visitor

Return Status at the time of a billing month

Trying to work through this myself but getting nowhere.

I have one table, PartnerStatus

PartnerName

StatusDateMovedToStatus
Partner ABronze7/1/2009
Partner ASilver7/1/2019
Partner BBronze7/1/2009
Partner BSilver7/1/2014
Partner BGold7/1/2016

 

Then I have a billings table, Billings

PartnerNameCommRunNetBilled
Partner A9/1/2015500
Partner A10/1/2015400
Partner A11/1/2015600
Partner B9/1/2015800
Partner B10/1/2015900
Partner B11/1/2015700

 

I need to figure out how to do a DAX calculated column that would take the DateMovedToStatus and see what Status the partner was in at that time.

I am trying to do it on a full year basis. so if they moved to Silver on 7/1/2015, then starting with the 1/1/2016 CommRun they status would be Silver

 

So the result table would be something like this

PartnerNameCommRunNetBilledStatus
Partner A12/1/2009400No Status
Partner A1/1/2010500Bronze
Partner A.........
Partner A12/1/2019600Bronze
Partner A1/1/2020800Silver
Partner B10/1/2014900Bronze
Partner B1/1/2015800Silver
Partner B.........
Partner B11/1/2016950Silver
Partner B1/1/20171200Gold

 

I've tried using a MAXX with filtering the table

MAXX(

FILTER(

PartnerStatus,
Billings[partnerid]=PartnerStatus[partnerid] &&
YEAR(PartnerStatus[DateMovedToStatus]<=EARLIER(Billings[Year])

),
PartnerStatus[Status]

)

 

but that only gave me the first status the partner was in. it missed all the subsequent status changes.

 

Any help out there?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@kuraitengai Maybe:

Column = 
  VAR __Date = [CommRun]
  VAR __Partner = [PartnerName]
  VAR __StatusDate = MAXX(FILTER('PartnerStatus', [PartnerName] = __Partner && [DateMovedToStatus] <= __Date),[DateMovedToStatus])
  VAR __Status = MAXX(FILTER('PartnerStatus', [PartnerName] = __Partner && [DateMovedToStatus] = __StatusDate),[Status])
  VAR __Result = IF( __Status = BLANK(), "No Status", __Status)
RETURN
  __Result

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@kuraitengai Maybe:

Column = 
  VAR __Date = [CommRun]
  VAR __Partner = [PartnerName]
  VAR __StatusDate = MAXX(FILTER('PartnerStatus', [PartnerName] = __Partner && [DateMovedToStatus] <= __Date),[DateMovedToStatus])
  VAR __Status = MAXX(FILTER('PartnerStatus', [PartnerName] = __Partner && [DateMovedToStatus] = __StatusDate),[Status])
  VAR __Result = IF( __Status = BLANK(), "No Status", __Status)
RETURN
  __Result

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 
This is great. I think that did it. Looking through the table with the calc column added to it.

 

I thought I did it as you typed, but i missed the < in the 

[DateMovedToStatus] <= __Date)

in the _StatusDate variable. It was only giving me silver in 2019 and gold in 2009. everything else was no status. added the <= and it filled in the years between.

 

Only change I made was to that variable. I did it as < instead of <=. wanted the status to not go into effect until the full calendar year after the status change. Just made that tweak, and it looks like it's working perfectly.

 

I'd originally tried to do it with variables, but when i read somewhere else about trying MAXX, i stopped using variables. Should have kept down that path.

 

Thanks for the help.

@kuraitengai Variables are your friends!!


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors