cancel
Showing results for
Did you mean:
Helper I

## sum if sum

can any one help me to write the script i want to get the result below

From Date Table and Data table

the rule is if sum of sales per week >=15 then it's 1, then i will need to sum the week based on period.

i got this by if( sum(sales)>=15,1,0), but i don't know how to sum it again by period

1 ACCEPTED SOLUTION
Community Support

According to your description, here's my solution.

1.The two tables are related with Date column.

2.Create a calculated column in Data table.

``WeekNo = RELATED('Date'[WeekNo])``

2.Create a measure.

``````Measure =
VAR _T =
'Data',
"Flag",
IF (
SUMX (
FILTER ( 'Data', 'Data'[WeekNo] = EARLIER ( 'Data'[WeekNo] ) ),
'Data'[Sales]
) > 15,
1,
0
)
/ COUNTROWS (
FILTER (
'Data',
'Data'[Veg] = EARLIER ( 'Data'[Veg] )
&& 'Data'[WeekNo] = EARLIER ( 'Data'[WeekNo] )
)
)
)
RETURN
SUMX ( _T, [Flag] )
``````

Get the correct result:

I attach my sample below for your reference.

Best Regards,
Community Support Team _ kalyj

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

3 REPLIES 3
Community Support

According to your description, here's my solution.

1.The two tables are related with Date column.

2.Create a calculated column in Data table.

``WeekNo = RELATED('Date'[WeekNo])``

2.Create a measure.

``````Measure =
VAR _T =
'Data',
"Flag",
IF (
SUMX (
FILTER ( 'Data', 'Data'[WeekNo] = EARLIER ( 'Data'[WeekNo] ) ),
'Data'[Sales]
) > 15,
1,
0
)
/ COUNTROWS (
FILTER (
'Data',
'Data'[Veg] = EARLIER ( 'Data'[Veg] )
&& 'Data'[WeekNo] = EARLIER ( 'Data'[WeekNo] )
)
)
)
RETURN
SUMX ( _T, [Flag] )
``````

Get the correct result:

I attach my sample below for your reference.

Best Regards,
Community Support Team _ kalyj

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

Super User

You can directly write measure as below:-

``Measure = IF(SUM('Table (2)'[sales])>= 15,1,0)``

Output:-

Refer a file below:-

Best Regards,
Samarth

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

Helper I

Hi @Samarth_18 , i get to this part, but i want the sum of weeks by period like this

Announcements

#### 2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

#### Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

#### Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

#### Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.

Top Solution Authors
Top Kudoed Authors