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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

If command

Hello,

I want to define no. of weeks for two cases in the table 'Geschäftskunden', but I get error:

 

Anzahl Woche =

VAR _StartDate = SELECTEDVALUE('Geschäftskunden'[Startdatum])

VAR _EndDate = SELECTEDVALUE('Geschäftskunden'[Enddatum])

RETURN

    IF (_EndDate = ISBLANK,

    DATEDIFF(_StartDate, Today(), WEEK)

    )

,

    IF (_EndDate = NOT ISBLANK,

    DATEDIFF(_StartDate, _EndDate, WEEK)

    )

2 ACCEPTED SOLUTIONS
bhanu_gautam
Super User
Super User

@Anonymous , Try using

DAX
Anzahl Woche =
VAR _StartDate = SELECTEDVALUE('Geschäftskunden'[Startdatum])
VAR _EndDate = SELECTEDVALUE('Geschäftskunden'[Enddatum])
RETURN
IF (
ISBLANK(_EndDate),
DATEDIFF(_StartDate, TODAY(), WEEK),
DATEDIFF(_StartDate, _EndDate, WEEK)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

v-ssriganesh
Community Support
Community Support

Hello @Anonymous,
Thank you for reaching out to the Microsoft Fabric Forum Community.

I have reproduced your scenario in Power BI Desktop using sample data, and I can confirm that the calculation is working as expected.

Summary of what I did:

  • Created a sample table Geschäftskunden with both populated and blank Enddatum values.
  • Used the following DAX formula in a calculated column to handle both cases correctly:
Anzahl Woche =

VAR _StartDate = 'Geschäftskunden'[Startdatum]

VAR _EndDate = 'Geschäftskunden'[Enddatum]

RETURN

IF(

    ISBLANK(_EndDate),

    DATEDIFF(_StartDate, TODAY(), WEEK),

    DATEDIFF(_StartDate, _EndDate, WEEK)

)

Result:
The column Anzahl Woche now shows the expected number of weeks:

  • When Enddatum is blank, it uses Today().
  • When Enddatum is present, it uses Enddatum.

I am attaching the sample .pbix file here for your reference so you can review and adapt it to your own dataset.

Thank you, @bhanu_gautam & @Ritaf1983 for sharing valuable insights.

 

If this information is helpful, please “Accept as solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

thanks

v-ssriganesh
Community Support
Community Support

Hello @Anonymous,
Thank you for reaching out to the Microsoft Fabric Forum Community.

I have reproduced your scenario in Power BI Desktop using sample data, and I can confirm that the calculation is working as expected.

Summary of what I did:

  • Created a sample table Geschäftskunden with both populated and blank Enddatum values.
  • Used the following DAX formula in a calculated column to handle both cases correctly:
Anzahl Woche =

VAR _StartDate = 'Geschäftskunden'[Startdatum]

VAR _EndDate = 'Geschäftskunden'[Enddatum]

RETURN

IF(

    ISBLANK(_EndDate),

    DATEDIFF(_StartDate, TODAY(), WEEK),

    DATEDIFF(_StartDate, _EndDate, WEEK)

)

Result:
The column Anzahl Woche now shows the expected number of weeks:

  • When Enddatum is blank, it uses Today().
  • When Enddatum is present, it uses Enddatum.

I am attaching the sample .pbix file here for your reference so you can review and adapt it to your own dataset.

Thank you, @bhanu_gautam & @Ritaf1983 for sharing valuable insights.

 

If this information is helpful, please “Accept as solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.

Anonymous
Not applicable

thank you very much, it works

bhanu_gautam
Super User
Super User

@Anonymous , Try using

DAX
Anzahl Woche =
VAR _StartDate = SELECTEDVALUE('Geschäftskunden'[Startdatum])
VAR _EndDate = SELECTEDVALUE('Geschäftskunden'[Enddatum])
RETURN
IF (
ISBLANK(_EndDate),
DATEDIFF(_StartDate, TODAY(), WEEK),
DATEDIFF(_StartDate, _EndDate, WEEK)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Anonymous
Not applicable

thank you

Anonymous
Not applicable

thanks

Ritaf1983
Super User
Super User

Hi @Anonymous 

The error comes from incorrect ISBLANK syntax and an extra IF. In DAX you must call ISBLANK() as a function, and IF takes three arguments (condition, value-if-TRUE, value-if-FALSE). A single expression does the job:

 

Anzahl Woche =
VAR _StartDate = SELECTEDVALUE ( 'Geschäftskunden'[Startdatum] )
VAR _EndDate = SELECTEDVALUE ( 'Geschäftskunden'[Enddatum] )
RETURN
IF (
ISBLANK ( _EndDate ),
DATEDIFF ( _StartDate, TODAY(), WEEK ),
DATEDIFF ( _StartDate, _EndDate, WEEK )
)

Things to double-check

Both columns are of Date data type.

If _StartDate might also be blank, wrap it in ISBLANK or use COALESCE.

For deeper troubleshooting, it’s best to share a sample PBIX or at least some mock data—upload to a public drive (OneDrive, Google Drive, etc.) and post the link.

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.