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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
bapt69
Helper I
Helper I

Dynamic column with period

Hi,

I didn't find out a post about it although I think at least one people were face to face with this situation.

 

Exemple : 

Historique (customers with statuts in each period) "d_client_histo"

client_idstart_dateend_datestatus
20001/01/202001/06/2022CLUB
200

01/06/2022

01/01/2100OR
10001/02/202101/01/2100CLUB

 

I got table DATE with relations DATE[date]=>start_date and DATE[date]=>end_date (only one active obviously)

And I got a table with all the status with his level

 

If one customer pass by a level over the CLUB's level -> his status-type is VIP

 

I would like to get these results :

If I choose year=2022

client_idstatuts_type
100CLUB
200

VIP

 

If I choose 2021

client_idstatuts_type
100CLUB
200CLUB

 

I tried this measure :

Max_statut = CALCULATE(
   MAX(d_client_histo[Niveau_statut]),
   USERELATIONSHIP(d_date[date],d_client_histo[date_debut]),
   USERELATIONSHIP(d_date[date],d_client_histo[date_fin]),
        FILTER(d_client_histo,
        d_client[client_id]=d_client_histo[client_id]
        &&d_client_histo[date_fin]<=MAX(d_date[date])
        &&d_client_histo[date_debut]>=MIN(d_date[date])))

 

Thank you all

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @bapt69 ,

 

Here I suggest you to create an unrelated calendar table to help you calculate the status.

Data model:

RicoZhou_0-1677825602789.png

Measure:

Status_Type = 
VAR _RANGESTART =
    MIN ( 'Calendar'[Date] )
VAR _RANGEEND =
    MAX ( 'Calendar'[Date] )
VAR _STATUSLIST =
    CALCULATETABLE (
        VALUES ( d_client_histo[status] ),
        FILTER (
            ALLEXCEPT ( d_client_histo, d_client_histo[client_id] ),
            d_client_histo[start_date] <= _RANGEEND
                && d_client_histo[end_date] >= _RANGESTART
        )
    )
VAR _COUNT =
    COUNTAX ( _STATUSLIST, [status] )
RETURN
    IF ( _COUNT = 1 && "CLUB" IN _STATUSLIST, "CLUB", "VIP" )

Result is as below.

RicoZhou_1-1677825632084.png

RicoZhou_2-1677825638858.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
bapt69
Helper I
Helper I

I did that :

Status_type =
VAR _RANGESTART =
    MIN (d_date[date])
VAR _RANGEEND =
    MAX (d_date[date])
VAR _STATUSLIST =
    CALCULATETABLE (
        VALUES (d_client_histo[Niveau_statut]),
        FILTER (
            ALLEXCEPT ( d_client_histo, d_client_histo[client_id] ),
            OR(OR(OR((d_client_histo[date_debut] <= _RANGESTART && d_client_histo[date_fin] >= _RANGESTART && d_client_histo[date_fin] <= _RANGEEND),
                (d_client_histo[date_debut] >= _RANGESTART && d_client_histo[date_fin] <= _RANGEEND)),
                (d_client_histo[date_debut] >= _RANGESTART && d_client_histo[date_debut] <= _RANGEEND && d_client_histo[date_fin] >= _RANGEEND)),
                (d_client_histo[date_debut] <= _RANGESTART && d_client_histo[date_fin] >= _RANGEEND))
        )
    )
VAR _COUNT =
    COUNTAX ( _STATUSLIST, d_client_histo[Niveau_statut] )
RETURN
    IF (AND( _COUNT >= 1,MAX(d_client_histo[Niveau_statut])>100), "VIP", "CLUB" )
 
That's good.
But I can't have a table like that (cause it's a measure) :
Status Type       Nb
VIP                    512
CLUB                 1532
 
Anonymous
Not applicable

Hi @bapt69 ,

 

Here I suggest you to create an unrelated calendar table to help you calculate the status.

Data model:

RicoZhou_0-1677825602789.png

Measure:

Status_Type = 
VAR _RANGESTART =
    MIN ( 'Calendar'[Date] )
VAR _RANGEEND =
    MAX ( 'Calendar'[Date] )
VAR _STATUSLIST =
    CALCULATETABLE (
        VALUES ( d_client_histo[status] ),
        FILTER (
            ALLEXCEPT ( d_client_histo, d_client_histo[client_id] ),
            d_client_histo[start_date] <= _RANGEEND
                && d_client_histo[end_date] >= _RANGESTART
        )
    )
VAR _COUNT =
    COUNTAX ( _STATUSLIST, [status] )
RETURN
    IF ( _COUNT = 1 && "CLUB" IN _STATUSLIST, "CLUB", "VIP" )

Result is as below.

RicoZhou_1-1677825632084.png

RicoZhou_2-1677825638858.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Alright,

First of all, thank you for your answer!

 

I customize your DAX with my fields :

Status_type =
VAR _RANGESTART =
    MIN (d_date[date])
VAR _RANGEEND =
    MAX (d_date[date])
VAR _STATUSLIST =
    CALCULATETABLE (
        VALUES (d_client_histo[Niveau_statut]),
        FILTER (
            ALLEXCEPT ( d_client_histo, d_client_histo[client_id] ),
            d_client_histo[date_debut] >= _RANGEEND
                || d_client_histo[date_fin] <= _RANGESTART
        )
    )
VAR _COUNT =
    COUNTAX ( _STATUSLIST, d_client_histo[Niveau_statut] )
RETURN
    IF ( _COUNT = 1 && 1000 IN _STATUSLIST, "VIP", "CLUB" )
 
Cause my field "statuts" is actually the status level (numeric)
I change the "<" and ">" (otherside). I want to exit the records wich have date_debut over the MAX(date) and the record which have date_fin under the MIN(date). So, I did right?
 
Question : the tables (histo and Date) HAVE TO be unrelated? or just no need to be related, anyway if it is?
 
Anyway, all my customers are "CLUB" and still be CLUB.
I'm gonna try to customize a little more to find out how to do it.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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