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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sarath_chandra
Helper III
Helper III

Dax Help

Hi all

plz help me in this

I need dax for dynamic week date select 

sarath_chandra_1-1673444620661.png

 

Expected output:

sarath_chandra_0-1673444573126.png

 

1 ACCEPTED SOLUTION
v-binbinyu-msft
Community Support
Community Support

Hi @sarath_chandra ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1673503308797.png

3. create three measure with below dax formula

Usage current week =
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Week Date] )
VAR cur_pn =
    SELECTEDVALUE ( 'Table'[PN] )
VAR _val =
    CALCULATE (
        MAX ( [Usage Value] ),
        'Table'[Week Date] = cur_date
            && 'Table'[PN] = cur_pn
    )
RETURN
    _val
Usage prior week =
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Week Date] )
VAR cur_pn =
    SELECTEDVALUE ( 'Table'[PN] )
VAR _val =
    CALCULATE (
        MAX ( 'Table'[Usage Value] ),
        WEEKNUM ( 'Table'[Week Date] )
            = WEEKNUM ( cur_date ) - 1
            && 'Table'[PN] = cur_pn
    )
RETURN
    _val
Difference = [Usage current week]-[Usage prior week]

3. add a slicer with "Table[Week Date]" field, add a table visual with field and measure

vbinbinyumsft_1-1673503523091.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
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
v-binbinyu-msft
Community Support
Community Support

Hi @sarath_chandra ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1673503308797.png

3. create three measure with below dax formula

Usage current week =
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Week Date] )
VAR cur_pn =
    SELECTEDVALUE ( 'Table'[PN] )
VAR _val =
    CALCULATE (
        MAX ( [Usage Value] ),
        'Table'[Week Date] = cur_date
            && 'Table'[PN] = cur_pn
    )
RETURN
    _val
Usage prior week =
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Week Date] )
VAR cur_pn =
    SELECTEDVALUE ( 'Table'[PN] )
VAR _val =
    CALCULATE (
        MAX ( 'Table'[Usage Value] ),
        WEEKNUM ( 'Table'[Week Date] )
            = WEEKNUM ( cur_date ) - 1
            && 'Table'[PN] = cur_pn
    )
RETURN
    _val
Difference = [Usage current week]-[Usage prior week]

3. add a slicer with "Table[Week Date]" field, add a table visual with field and measure

vbinbinyumsft_1-1673503523091.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Syndicate_Admin
Administrator
Administrator

there @Syndicate_Admin

not sure if i fully get you, you may try to plot the expected table with measures like this:

UsageCurrentWeek =
VAR _date = MAX(TableName[week date])
SUMX(
    FILTER(TableName, TableName[week date] =  _date ),
    TableName[usage value]
)

UsagePriorWeek =
VAR _date = MAX(TableName[week date])
SUMX(
    FILTER(TableName, WEEKNUM(TableName[week date]) =  WEEKNUM(_date) -1 ),
    TableName[usage value]
)

difference = UsageCurrentWeek - UsagePriorWeek

p.s. please consider use English for further post.

sarath_chandra
Helper III
Helper III

@bolfri @Idrisshatila @FreemanZ please help me out

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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