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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

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

@Anonymous 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

Follow on LinkedIn
@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@Anonymous 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

Follow on LinkedIn
@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@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.

@Anonymous Variables are your friends!!


Follow on LinkedIn
@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.