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
AndrejZitnay
Post Patron
Post Patron

VAT Payment every July, October, January & April

Hello all,

 

Would you be so kind and hlep me with measure for my VAT payments?

 

I have VAT as measure [VAT] and date from date table which is linked to my mesure via relationshop where I have dates as [MMM-YY"] but for calucation I use [MM/DD/YYYY]

 

I have always only one day in month and there are no gaps.

 

I know how to calculate cumulatives but I don't know how to calulacate sum for previews 3 months

 

Jan VAT  payment is = sum of Oct,Nov & Dec

Apr VAT paymet is = sum of Jan, Feb & March

July VAT payment is = sum of Apr, May & June

Oct VAT payment is = sum of Jul, Aug & Sep

 

etc for few years

 

 

VAT Payment.JPG

 

Many thanks.

 

Andrej

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@AndrejZitnay , In you date table create a flag

 

flag = if(month([Date] in {1,4,7,10}, 1,0)

 

then try a measure like this and filter the page of visual on above flag

 

Rolling 3 = CALCULATE(sum(Table[Amount]),DATESINPERIOD('Date'[Date ],eomonth(MAX('Date'[Date]),-1) ,-3,MONTH))

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@AndrejZitnay , In you date table create a flag

 

flag = if(month([Date] in {1,4,7,10}, 1,0)

 

then try a measure like this and filter the page of visual on above flag

 

Rolling 3 = CALCULATE(sum(Table[Amount]),DATESINPERIOD('Date'[Date ],eomonth(MAX('Date'[Date]),-1) ,-3,MONTH))

Anonymous
Not applicable

@amitchandak 

 

Hi Amit, I have a doubt. Will a time intelligence function always work correctly and give accurate results under all scenarios in the absence of a calendar table or tables with missing dates in the date column? Especially so when it is not marked as a "Date Table".  @AndrejZitnay  said his table has only one date per month. In that scenario, I felt skeptical about using a time intelligence function.

 

Also, in this article at sqlbi by @marcorusso  https://www.sqlbi.com/articles/time-intelligence-in-power-bi-desktop/  , it was suggested to add an ALL(<datefield>) to the CALCULATE function in the absence of a date table.

 

What is the implication here? 

Hello @amitchandak ,

 

Thank you. It does work. 

 

CF VAT Cashflow calc = CALCULATE([VAT Base for VAT Cashflow],DATESINPERIOD(PayMonthTable[PayMonth-cost],eomonth(MAX(PayMonthTable[PayMonth-cost]),-1) ,-3,MONTH))*SUMX(PayMonthTable,PayMonthTable[flag])

 

MonthCalendar.jpg

Anonymous
Not applicable

Hi,

There are many ways to handle this kind of calculation either by using the internal Date/Time intelligence functions or by way of writing your own Date/Time calculations in DAX. But in almost all the cases involving Date/Time intelligence calculations, the calculation relies on having a calendar table with all the dates in the year without any gaps and marking it as a date table. To write such measures, the awareness about the various relationships to the calendar table is also mandatory, otherwise, the formula will look correct, but the result will be wrong and unless you already know the result and able to cross-verify, there is no way a user will be able to know if the result is correct or not.

 

You mentioned that your table has only one date per month... (If I understood it correctly), therefore I am not suggesting any time intelligence functions or similar custom functions, instead, we will use only two functions RANK (to rank the dates in ascending order) and a MONTH (to determine the calendar month number) to arrive at the solution.

 

Given below is the solution:

Assuming there is a table named "VAT Data" with the following sample data.

DateVAT
31-05-20212
30-06-20213
31-07-20214
31-08-20215
30-09-20216
31-10-20217
30-11-20218
31-12-20219
31-01-202210
28-02-202211
31-03-202212
30-04-202213
31-05-202214
30-06-202215
31-07-202216
31-08-202217
30-09-202218
31-10-202219
30-11-202220
31-12-202221
31-01-202322

 

Add four calculated columns to this table using the following expressions.

 

 

Date Rank =
RANKX ( 'VAT Data', 'VAT Data'[Date], 'VAT Data'[Date], ASC, DENSE )
VAT Payment From = 'VAT Data'[Date Rank]-3
VAT Payment To = 'VAT Data'[Date Rank]-1
MonthNumber = MONTH('VAT Data'[Date])

 

 

The table will now look like this...

DateMonthly VATDate RankVAT Payment FromVAT Payment ToMonthNumber
31 May 202121-205
30 June 202132-116
31 July 202143027
31 August 202154138
30 September 202165249
31 October 2021763510
30 November 2021874611
31 December 2021985712
31 January 2022109681
28 February 20221110792
31 March 202212118103
30 April 202213129114
31 May 2022141310125
30 June 2022151411136
31 July 2022161512147
31 August 2022171613158
30 September 2022181714169
31 October 20221918151710
30 November 20222019161811
31 December 20222120171912
31 January 2023222118201

 

Now create a measure named  VAT Payment with the following code.

 

 

 

VAT Payment =
VAR CurrentMonth =
    SELECTEDVALUE ( 'VAT Data'[Date Rank] )
VAR FromMonth = CurrentMonth - 3
VAR ToMonth = CurrentMonth - 1
VAR Amount =
    SUMX (
        FILTER (
            ALL ( 'VAT Data' ),
            'VAT Data'[Date Rank] >= FromMonth
                && 'VAT Data'[Date Rank] <= ToMonth
        ),
        'VAT Data'[Monthly VAT]
    )
VAR CurrentMonthNumber =
    SELECTEDVALUE ( 'VAT Data'[MonthNumber] )
VAR ReturnValue =
    IF ( CurrentMonthNumber IN { 1, 4, 7, 10 }, Amount, BLANK () )
RETURN
    ReturnValue

 

 

 This will give the following result.

pbi.png

Actually, the DAX code mentioned here uses a very rudimentary approach without using any of the inbuilt date/time intelligence functions. I have not worried about the best or efficient method, and just used what suits this scenario where there is no standard date table available and only one date is there for every month. 

 

But if you could change to a standard model with a proper date table, you can rewrite the entire thing using a combination of functions like SUMX, EDATE, STARTOFTHEMONTH, ENDOFTHEMONTH, DATESBETWEEN, SELECTEDVALUE etc...

 

It is up to you whether to change the data model for the sake of using such functions or just use the functions that fit the current model. 

 

 

Hello @Anonymous ,

 

Many thanks for your help.

I've tried to follow your guiadance but I have no otucome. 

(There is no error in formula just result is blank)

Did I missed anything?

 

My VAT Base comes from this measrue 

 

VAT Base for VAT Cashflow = CALCULATE(SUMX(PayMonthTable,[CF Input VAT (131CF)]+[CF Income Vat (93CF)]))

 

CF VAT Cashflow calc = VAR CurrentMonth =
SELECTEDVALUE ( 'PayMonthTable'[PayMonth-cost] )
VAR FromMonth = CurrentMonth - 3
VAR ToMonth = CurrentMonth - 1
VAR Amount =
SUMX (
FILTER (
ALL ( PayMonthTable ),
PayMonthTable[VAT Payment From] >= FromMonth
&& PayMonthTable[VAT Payment To] <= ToMonth
),
[VAT Base for VAT Cashflow]
)
VAR CurrentMonthNumber =
SELECTEDVALUE ( PayMonthTable[MonthNumberNew] )
VAR ReturnValue =
IF ( CurrentMonthNumber IN { 1, 4, 7, 10 }, Amount, BLANK () )
RETURN
ReturnValue


 

 

Blanks result.JPGMonthCalendar.jpg

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.

Top Solution Authors