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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Syndicate_Admin
Administrator
Administrator

Help with calculated column

Power BI Community, Cordial Greeting.

I'm around to ask you for a big help with a calculated column that I want to make.

I have 2 boards, 1. Semanas_Epidemiologica and 2. Report table, in table number 2 of reports I want to add a new column where I get according to the date of enrollment to which week corresponds from the table Semanas_Epidemiologica,as well:

1. Table of Semanas_Epidemiologica

Fec_Ini_SemFec_Fin_SemSem_Epi
29/12/201904/01/2020No 1
05/01/202011/01/2020Without 2
12/01/202018/01/2020No 3
19/01/202025/01/2020No 4
26/01/202001/02/2020No 5
02/02/202008/02/2020No 6
09/02/202015/02/2020No 7
16/02/202022/02/2020No 8
23/02/202029/02/2020No 9
01/03/202007/03/2020No 10
08/03/202014/03/2020No 11

2. Reporting table

UserFecha_InscripcionSem_Epi
12303/01/2020???
54620/01/2020???
13405/03/2020???
45806/01/2020???
98707/02/2020???
25418/02/2020???
15829/01/2020???
98710/01/2020???

Expected result reporting table

UserFecha_IncripcionSem_Epi
12303/01/2020No 1
54620/01/2020No 4
13405/03/2020No 10
45806/01/2020Without 2
98707/02/2020No 6
25418/02/2020No 8
15829/01/2020No 5
98710/01/2020Without 2

I hope I've put everything in place so they understand me and can help me.

Thank you very much in advance.

Walter

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Don'@Syndicate_Admin,

According to my understanding, you want to get the last [sem_Epi] fromtable1 when [Fecha_Inscripcion]is before [Fec_Fin_Sem], right?

As @Vera_33 suggest, you can use the MINX() and LOOKUPVALUE() functions to do this,

Sem_Epi =
VAR _date = [Fecha_Inscripcion]
VAR _near =
    MINX (
        FILTER (
            'Table of Semanas_Epidemiologica',
            'Table of Semanas_Epidemiologica'[Fec_Fin_Sem] >= _date
        ),
        [Fec_Fin_Sem]
    )
RETURN
    LOOKUPVALUE ( 'Table of Semanas_Epidemiologica'[Sem_Epi], [Fec_Fin_Sem], _near )

Or to make it easier to understand, use the following formula:

Sem_Epi 2 =
VAR _date = [Fecha_Inscripcion]
VAR _near =
    CALCULATE (
        MIN ( 'Table of Semanas_Epidemiologica'[Fec_Fin_Sem] ),
        FILTER (
            'Table of Semanas_Epidemiologica',
            'Table of Semanas_Epidemiologica'[Fec_Fin_Sem] >= _date
        )
    )
RETURN
    CALCULATE (
        MAX ( 'Table of Semanas_Epidemiologica'[Sem_Epi] ),
        FILTER (
            'Table of Semanas_Epidemiologica',
            'Table of Semanas_Epidemiologica'[Fec_Fin_Sem] = _near
        )
    )

The final output is shown below:

2.15.3.1.PNG

You could take a look at the pbix file here.


Best regards
Eyelyn Qin
If this post helps, then consider Accept it as the solution to help other members find it faster.

View solution in original post

5 REPLIES 5
parry2k
Super User
Super User

@Syndicate_Admin you should mark the correct post as a solution so that others can take advantage of it rather than marking your own reply as a solution. Just advice.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Syndicate_Admin
Administrator
Administrator

Excellent, thank you very much friends, I worked perfectly.

They're the best 😃

Anonymous
Not applicable

Don'@Syndicate_Admin,

According to my understanding, you want to get the last [sem_Epi] fromtable1 when [Fecha_Inscripcion]is before [Fec_Fin_Sem], right?

As @Vera_33 suggest, you can use the MINX() and LOOKUPVALUE() functions to do this,

Sem_Epi =
VAR _date = [Fecha_Inscripcion]
VAR _near =
    MINX (
        FILTER (
            'Table of Semanas_Epidemiologica',
            'Table of Semanas_Epidemiologica'[Fec_Fin_Sem] >= _date
        ),
        [Fec_Fin_Sem]
    )
RETURN
    LOOKUPVALUE ( 'Table of Semanas_Epidemiologica'[Sem_Epi], [Fec_Fin_Sem], _near )

Or to make it easier to understand, use the following formula:

Sem_Epi 2 =
VAR _date = [Fecha_Inscripcion]
VAR _near =
    CALCULATE (
        MIN ( 'Table of Semanas_Epidemiologica'[Fec_Fin_Sem] ),
        FILTER (
            'Table of Semanas_Epidemiologica',
            'Table of Semanas_Epidemiologica'[Fec_Fin_Sem] >= _date
        )
    )
RETURN
    CALCULATE (
        MAX ( 'Table of Semanas_Epidemiologica'[Sem_Epi] ),
        FILTER (
            'Table of Semanas_Epidemiologica',
            'Table of Semanas_Epidemiologica'[Fec_Fin_Sem] = _near
        )
    )

The final output is shown below:

2.15.3.1.PNG

You could take a look at the pbix file here.


Best regards
Eyelyn Qin
If this post helps, then consider Accept it as the solution to help other members find it faster.

Vera_33
Resident Rockstar
Resident Rockstar

Hi @Syndicate_Admin @WolterNet 

 

You don't have duplicated weeks in Table1, right?

 

Cal Column =

VAR CurDate = Table2[Fecha_Inscripcion]
VAR MinDate = MINX(FILTER(Table1,Table1[Fec_Fin_Sem]>=CurDate),[Fec_Ini_Sem])
RETURN
LOOKUPVALUE(Table1[Sem_Epi],Table1[Fec_Ini_Sem],MinDate)
parry2k
Super User
Super User

@Syndicate_Admin use the following DAX expression to add a column:

 

Sem_Epi = 
VAR _t = 
CALCULATETABLE ( 
    Seman,
    FILTER ( 
        Seman, 
        Seman[Fec_Fin_Sem]  >= Reporting[Fecha_Inscripcion]
   ) 
) 
VAR _d = 
CALCULATE ( 
    MIN ( Seman[Sem_Epi] ),
    TOPN ( 1, _t, [Fec_Fin_Sem], ASC )
)
RETURN _d 

 

Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.