SELECT 
    Week,
    segment,
    internal_service,
    ownership_type,
    purchase_type,
    SUM_IF(cube_revenue_w_cpa, commerce_type = 'commerce' AND fraud_type = 'normal') AS Revenue
FROM hahn.`home/mcsanalytics/kalamkas/yan_cube_shortened_v1`
WHERE 1 = 1
AND NVL(network_type, 'unknown') || ' - ' || NVL(ownership_type, 'unknown') IN ('yan - external', 'yan - internal')
AND cube_revenue_w_cpa <> 0
GROUP BY 
    Week,
    segment,
    internal_service,
    NVL(ownership_type, 'unknown') AS ownership_type,
    purchase_type


