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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Complex calculation

I have below data set in my SSAS tabular model, for time being i have posted data for one month but the actual dataset contains number of months.

 

 

Requirement - If any day data missing in a particular month we have to apply the below logic.  in the below case data was missed for 29-Mar-18 ,

 

Get the before all last four weeks total

(17,936.92 + 21,222.56 + 16,338.08 + 14,054.56 ) / 4  =  17,388.03

 

and get the prevoius day value of the missing day = 38,057.32

 

and calculate the  percentage (38,057.32 / 17,388.03) * 100 = 218 percent 

 

 

Now i have to create below report which is showing the total sales amount for march, In case if any month has missing date then we have to apply the above logic and calculate the percent and If the Percentage is greater than 210 % then only we should show the total sales value for than particular month otherwise we have to show blank. In case if data consists for all days in a month then it should be straight forward sum otherwise if any day misses we have to apply the above logic and decide to show are not to show value in the report.

 

 

 

Seial NoCalenderDateAmountDayName
128-Feb-1817,936.92Wed
21-Mar-18$15,762.60Thu
32-Mar-18$16,575.20Fri
43-Mar-18$11,510.84Sat
54-Mar-18$7,402.72Sun
65-Mar-18$17,666.52Mon
76-Mar-18$17,119.92Tue
87-Mar-1821,222.56Wed
98-Mar-18$17,005.28Thu
109-Mar-18$19,470.16Fri
1110-Mar-18$12,438.08Sat
1211-Mar-18$9,739.52Sun
1312-Mar-18$15,171.64Mon
1413-Mar-18$13,884.84Tue
1514-Mar-1816,338.08Wed
1615-Mar-18$14,875.76Thu
1716-Mar-18$16,716.36Fri
1817-Mar-18$13,023.04Sat
1918-Mar-18$9,731.24Sun
2019-Mar-18$15,625.92Mon
2120-Mar-18$14,654.92Tue
2221-Mar-1814,054.56Wed
2322-Mar-18$16,035.64Thu
2423-Mar-18$20,539.36Fri
2524-Mar-18$14,389.20Sat
2625-Mar-18$11,889.92Sun
2726-Mar-18$16,035.76Mon
2827-Mar-18$20,404.36Tue
2928-Mar-1838,057.32Wed
3029-Mar-18 Thu
3130-Mar-18$21,573.36Fri
3 REPLIES 3
v-yulgu-msft
Employee
Employee

Hi @Anonymous,

 

Based on my understanding, you may need below formula:

Total sales per month =
VAR previousweekday =
    CALCULATE (
        LASTNONBLANK ( TableA[DayName], 1 ),
        FILTER ( TableA, TableA[Seial No] < EARLIER ( TableA[Seial No] ) )
    )
VAR totallastfourweeks =
    IF (
        TableA[Amount] = BLANK (),
        CALCULATE (
            SUM ( TableA[Amount] ),
            FILTER (
                TableA,
                TableA[Seial No]
                    <= EARLIER ( TableA[Seial No] ) - 8
                    && TableA[Seial No]
                        >= EARLIER ( TableA[Seial No] ) - 29
                    && TableA[DayName] = previousweekday
            )
        )
            / 4,
        BLANK ()
    )
VAR prevoiusdayvalue =
    IF (
        TableA[Amount] = BLANK (),
        CALCULATE (
            LASTNONBLANK ( TableA[Amount], 1 ),
            FILTER ( TableA, TableA[Seial No] = EARLIER ( TableA[Seial No] ) - 1 )
        )
    )
VAR percentvalue =
    IF (
        TableA[Amount] = BLANK (),
        TableA[prevoius day value] / TableA[last four weeks total],
        BLANK ()
    )
VAR countblankamount =
    CALCULATE (
        COUNT ( TableA[Seial No] ),
        FILTER (
            TableA,
            TableA[CalenderDate].[Year] = EARLIER ( TableA[CalenderDate].[Year] )
                && TableA[CalenderDate].[Month] = EARLIER ( TableA[CalenderDate].[Month] )
                && TableA[Amount] = BLANK ()
        )
    )
VAR MonthTotal =
    CALCULATE (
        SUM ( TableA[Amount] ),
        ALLEXCEPT ( TableA, TableA[CalenderDate].[Year], TableA[CalenderDate].[Month] )
    )
RETURN
    IF ( totallastfourweeks >= 1 && percentvalue < 0.21, BLANK (), MonthTotal )

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Category

CalenderDate

Amount

DayName

1

28-Feb-18

17,936.92

Wed

1

1-Mar-18

$15,762.60

Thu

1

2-Mar-18

$16,575.20

Fri

1

3-Mar-18

$11,510.84

Sat

1

4-Mar-18

$7,402.72

Sun

1

5-Mar-18

$17,666.52

Mon

1

6-Mar-18

$17,119.92

Tue

1

7-Mar-18

21,222.56

Wed

1

8-Mar-18

$17,005.28

Thu

1

9-Mar-18

$19,470.16

Fri

1

10-Mar-18

$12,438.08

Sat

1

11-Mar-18

$9,739.52

Sun

1

12-Mar-18

$15,171.64

Mon

1

13-Mar-18

$13,884.84

Tue

1

14-Mar-18

16,338.08

Wed

1

15-Mar-18

$14,875.76

Thu

1

16-Mar-18

$16,716.36

Fri

1

17-Mar-18

$13,023.04

Sat

1

18-Mar-18

$9,731.24

Sun

1

19-Mar-18

$15,625.92

Mon

1

20-Mar-18

$14,654.92

Tue

1

21-Mar-18

14,054.56

Wed

1

22-Mar-18

$16,035.64

Thu

1

23-Mar-18

$20,539.36

Fri

1

24-Mar-18

$14,389.20

Sat

1

25-Mar-18

$11,889.92

Sun

1

26-Mar-18

$16,035.76

Mon

1

27-Mar-18

$20,404.36

Tue

1

28-Mar-18

38,057.32

Wed

1

29-Mar-18

 

Thu

1

30-Mar-18

$21,573.36

Fri

2

1-Mar-18

$15,762.60

Thu

2

2-Mar-18

$16,575.20

Fri

2

3-Mar-18

$11,510.84

Sat

2

4-Mar-18

$7,402.72

Sun

2

5-Mar-18

$17,666.52

Mon

2

6-Mar-18

$17,119.92

Tue

2

7-Mar-18

$21,222.56

Wed

2

8-Mar-18

$17,005.28

Thu

2

9-Mar-18

$19,470.16

Fri

2

10-Mar-18

$12,438.08

Sat

2

11-Mar-18

$9,739.52

Sun

2

12-Mar-18

$15,171.64

Mon

2

13-Mar-18

$13,884.84

Tue

2

14-Mar-18

$16,338.08

Wed

2

15-Mar-18

$14,875.76

Thu

2

16-Mar-18

$16,716.36

Fri

2

17-Mar-18

$13,023.04

Sat

2

18-Mar-18

$9,731.24

Sun

2

19-Mar-18

$15,625.92

Mon

2

20-Mar-18

$14,654.92

Tue

2

21-Mar-18

$14,054.56

Wed

2

22-Mar-18

$16,035.64

Thu

2

23-Mar-18

$20,539.36

Fri

2

24-Mar-18

$14,389.20

Sat

2

25-Mar-18

$11,889.92

Sun

2

26-Mar-18

$16,035.76

Mon

2

27-Mar-18

$20,404.36

Tue

2

28-Mar-18

$38,057.32

Wed

2

29-Mar-18

$100.00

Thu

2

30-Mar-18

$21,573.36

Fri

2

31-Mar-18

$400.00

Sat

 

 

I really appreciate your help, I have small modification in the requirement.

 

We have multiple category’s for a given month and the data missed for the date will not be available in the transaction fact table so we have to join with date table and identify those records?

 

 I have added serial number for my reference, but it doesn’t exist in the fact table.

 

If you observe, the below set i have added additional field category for category = 1 we have missing dates and for category = 2 we don’t have any missing dates.

 

So the percentage logic should be applied to only category = 1 since it has missing records and category = 2 we should keep as is because it doesn’t have any missing dates.

 

So if we apply yesterday’s logic then it should ignore only records from category = 1 if the percent is less than 210, but the category = 2 records should be added to the aggregates without having any additional logic because it consists of all dates.

 

There could be many categories for time being i have included only two in the dataset category 1 and cateroy 2.

 

There could be multiple entries for same category for a same date. We also have to consider this.

 

And also we have to create a Slicer in the UI with Yes or No , If user select Yes Then we have to apply the missing dates logic and check the percentage logic and if user select No then it should aggregate all values irrespective of missing dates and percentage logic.

Anonymous
Not applicable

Can anyone please help me with the solution.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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