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
memasarif
New Member

Add rows if it is the last day of the month and if it is in weekdays

Dear All,

 

I would like to sum the rows for val if they are last day of the month and if they are in the weekdays. If last day of the month corresponds to either saturday or sunday then sum friday. What could be the formula? I need e general formula to add. I have several months in my table.

 

Thank you.lastday.png 

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

Hi @memasarif ,

 

Would you please refer to the measure below:

 

Measure =
VAR a =
    ADDCOLUMNS (
        SUMMARIZE (
            'Table',
            'Table'[Date],
            'Table'[Val],
            "weekday", WEEKDAY ( 'Table'[Date], 2 ),
            "weeknum", WEEKNUM ( 'Table'[Date] ),
            "eomonth", EOMONTH ( 'Table'[Date], 0 )
        ),
        "lastworkday",
            IF (
                'Table'[Date] = [eomonth],
                IF ( [weekday] <= 5, 1, 0 ),
                IF ( [weekday] = 5 && [weeknum] = WEEKNUM ( [eomonth] ), 1, 0 )
            )
    )
RETURN
    SUMX ( FILTER ( a, [lastworkday] = 1 ), 'Table'[Val] )

 

 

For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/ER3TmlaekNFKjActYx...

 

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

 

Best Regards,

Dedmon Dai

View solution in original post

3 REPLIES 3
v-deddai1-msft
Community Support
Community Support

Hi @memasarif ,

 

Would you please refer to the measure below:

 

Measure =
VAR a =
    ADDCOLUMNS (
        SUMMARIZE (
            'Table',
            'Table'[Date],
            'Table'[Val],
            "weekday", WEEKDAY ( 'Table'[Date], 2 ),
            "weeknum", WEEKNUM ( 'Table'[Date] ),
            "eomonth", EOMONTH ( 'Table'[Date], 0 )
        ),
        "lastworkday",
            IF (
                'Table'[Date] = [eomonth],
                IF ( [weekday] <= 5, 1, 0 ),
                IF ( [weekday] = 5 && [weeknum] = WEEKNUM ( [eomonth] ), 1, 0 )
            )
    )
RETURN
    SUMX ( FILTER ( a, [lastworkday] = 1 ), 'Table'[Val] )

 

 

For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/ER3TmlaekNFKjActYx...

 

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

 

Best Regards,

Dedmon Dai

Greg_Deckler
Super User
Super User

@memasarif - Thinking something like:

Measure =
  VAR __Date = MAX([DATE])
  VAR __Table = 'Table'
  VAR __Table1
    ADDCOLUMNS(
      __Table,
      "FinalVal",
        SWITCH([DAY NAME]),
          "SUNDAY",SUMX(FILTER(__Table,[DATE]=__Date-2),[VAL]),
          "SATURDAY",SUMX(FILTER(__Table,[DATE]=__Date-1),[VAL]),
          [VAL]
        )
     )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
sreenub
Resolver II
Resolver II

Please find below Mesure to find last working day balance .
 
Last workinng day BalanceAmount =
CALCULATE (
SUM ( Fact[BalanceAmount] ),
FILTER ( DimDate, DimDate[Date] = MAX ( DimDate[Date] ) && DimDate[Weekdaynumber]<6)
)

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.