Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculated difference #403

Open
jamesrkg opened this issue Apr 27, 2021 · 6 comments
Open

Calculated difference #403

jamesrkg opened this issue Apr 27, 2021 · 6 comments

Comments

@jamesrkg
Copy link

@jjdelc are you able to add support for Calculated differences?

https://crunch.io/dev/features/subtotal-differences/

@jjdelc
Copy link
Contributor

jjdelc commented Apr 30, 2021

Yeah, I see there's a .add_subtotal I will read through that and see how it would be best to add the subtotal differences there

@jjdelc
Copy link
Contributor

jjdelc commented May 4, 2021

How does this look:

var.add_subtotal("F - M", {
            "add": ["Female"],
            "minus": ["Male"]
        }, anchor="bottom")

It is overloading the Variable.add_subtotal method to detect if the 2nd argument (the categories) is a dictionary, we will use those values as positive and negative.

Another alternative is to have a separate function for when you want the subtotal to include substractions, like:

var.add_subtotal_differences("F - M", ["Female"], ["Male"], anchor="bottom")

@jamesrkg
Copy link
Author

jamesrkg commented May 5, 2021

A new method would be cleaner, I believe. Following from your example I imagine usage such as:

var = var.add_subtotal(name="Promoters", categories=[9, 10], anchor="bottom")
var = var.add_subtotal(name="Detractors", categories=[1, 2, 3, 4, 5, 6], anchor="bottom")
var = var.add_subtotal_difference(name="NPS", add=["Promoters"], subtract=["Detractors"], anchor="bottom")

Any reason why the add/subtract args should be lists? Can we simplify to str or is this future-proofing a use case I'm not aware of?

@jamesrkg
Copy link
Author

jamesrkg commented May 5, 2021

@jjdelc is it possible to add a difference calculation without creating/showing its dependent subtotals? For example would it be possible to add an NPS without adding Promoter and Detractor subtotals?

Perhaps I misunderstood your original example and "Female"/"Male" were category names rather than subtotal names?

If so, would this kind of usage be viable?

var = var.add_subtotal_difference(name="NPS", add=[9, 10], subtract=[1, 2, 3, 4, 5, 6], anchor="bottom")

@jjdelc
Copy link
Contributor

jjdelc commented May 5, 2021

Yes, the subtotal does not need to show the previous ones. but you have to indicate the items:

var = var.add_subtotal_difference(name="NPS", add=[9, 10], subtract=[1, 2, 3, 4, 5, 6], anchor="bottom")

In my example, I was abusing the fact that you can indicate either category IDs or category names.

@jamesrkg
Copy link
Author

jamesrkg commented May 6, 2021

Ok great - this is preferable to my original assumption about naming subtotals anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants