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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Chandu_sandy
Frequent Visitor

Dax formula to get week data

I have a scenario where i have 2 months data i.e., 2023 december 5 weeks and 2024 january 2 weeks(till today) 
so i need to show the data in a bar chart as  jan1st week with december 1st week, jan 2nd week with december 2nd week and so on jan dont have next weeks data but december should show the data. 

is there any way to achieve it ?

2 ACCEPTED SOLUTIONS
hvnter
Resolver I
Resolver I

You can create a 'WeekOfMonth' column on your Date Dimension that assigns the WeekOfMonth number by the Week Ending date.  Then you can write DAX variables to leverage the WeekOfMonth Number to get your comps in your DAX measure(s)

View solution in original post

Anonymous
Not applicable

Hi @Chandu_sandy ,

I created some simple data to help you solve the problem, you can follow these steps below:

1.Create a new table.

 

Table =
VAR _table =
    ADDCOLUMNS (
        CALENDAR ( DATE ( 2023, 12, 1 ), TODAY () ),
        "Week", WEEKNUM ( [Date] ),
        "Month", MONTH ( [Date] )
    )
RETURN
    _table

 

 

2.Create a new column.

 

MonthWeek =
VAR _1 =
    WEEKNUM ( [Date] ) - WEEKNUM ( DATE ( 2023, 12, 1 ) ) + 1
RETURN
    IF ( 'Table'[Week] > 6, _1, 'Table'[Week] )

 

 

 

total =
CALCULATE (
    SUM ( 'Table'[SalesAmount] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Month] = EARLIER ( 'Table'[Month] )
            && 'Table'[MonthWeek] = EARLIER ( 'Table'[MonthWeek] )
    )
)

 

 

Final output:

vyifanwmsft_0-1705298010172.png

 

vyifanwmsft_1-1705298036798.png

 

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Yifan Wang

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

2 REPLIES 2
Anonymous
Not applicable

Hi @Chandu_sandy ,

I created some simple data to help you solve the problem, you can follow these steps below:

1.Create a new table.

 

Table =
VAR _table =
    ADDCOLUMNS (
        CALENDAR ( DATE ( 2023, 12, 1 ), TODAY () ),
        "Week", WEEKNUM ( [Date] ),
        "Month", MONTH ( [Date] )
    )
RETURN
    _table

 

 

2.Create a new column.

 

MonthWeek =
VAR _1 =
    WEEKNUM ( [Date] ) - WEEKNUM ( DATE ( 2023, 12, 1 ) ) + 1
RETURN
    IF ( 'Table'[Week] > 6, _1, 'Table'[Week] )

 

 

 

total =
CALCULATE (
    SUM ( 'Table'[SalesAmount] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Month] = EARLIER ( 'Table'[Month] )
            && 'Table'[MonthWeek] = EARLIER ( 'Table'[MonthWeek] )
    )
)

 

 

Final output:

vyifanwmsft_0-1705298010172.png

 

vyifanwmsft_1-1705298036798.png

 

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Yifan Wang

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

hvnter
Resolver I
Resolver I

You can create a 'WeekOfMonth' column on your Date Dimension that assigns the WeekOfMonth number by the Week Ending date.  Then you can write DAX variables to leverage the WeekOfMonth Number to get your comps in your DAX measure(s)

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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